Skip to content

Instantly share code, notes, and snippets.

@felangel
Created December 26, 2018 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/4b90d62c0c09dad712e22a634a1fe0f8 to your computer and use it in GitHub Desktop.
Save felangel/4b90d62c0c09dad712e22a634a1fe0f8 to your computer and use it in GitHub Desktop.
StatefulWidget Issues
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