Created
December 26, 2018 05:08
-
-
Save felangel/4b90d62c0c09dad712e22a634a1fe0f8 to your computer and use it in GitHub Desktop.
StatefulWidget Issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Example'), | |
), | |
body: PageA(), | |
), | |
), | |
); | |
} | |
class PageA extends StatefulWidget { | |
@override | |
_PageAState createState() => _PageAState(); | |
} | |
class _PageAState extends State<PageA> { | |
List<String> texts; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
PageB(this.texts), | |
RaisedButton( | |
child: Text('Get Details'), | |
onPressed: () => getDetails(), | |
), | |
], | |
); | |
} | |
Future<void> getDetails() async { | |
var texts = await Future.value(['hi']); | |
setState(() { | |
this.texts = texts; | |
}); | |
} | |
} | |
class PageB extends StatefulWidget { | |
final List<String> text; | |
PageB(this.text); | |
@override | |
_PageBState createState() => _PageBState(); | |
} | |
class _PageBState extends State<PageB> { | |
@override | |
Widget build(BuildContext context) { | |
return someAnimation(); | |
} | |
Widget someAnimation() { | |
return Container( | |
child: Center( | |
child: Text( | |
'Details: ${widget.text.toString()}', | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment