현재 6.3.2절의 StatefullWidget 클래스의 동작을 확인하고 있습니다.
코드는 잘 동작합미다만,
책에서는 SecondStatefullPage가 생성이 될 때 뒤에 있는 FirstStatefullPage도 같이 그려진다고 되어 있는데
로그에선 SecondStatefullPage만 그려졌습니다.
어떤 부분이 잘못되었는지 잘 모르겠네요.
확인 좀 부탁드립니다.
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: FirstStatefulPage(),
);
}
}
class Person{
String name;
int age;
Person(this.name, this.age);
}
class FirstStatefulPage extends StatefulWidget {
@OverRide
_FirstStatefulPageState createState() => _FirstStatefulPageState();
}
class _FirstStatefulPageState extends State {
@OverRide
Widget build(BuildContext context) {
print('FirstPage build() - ');
return Scaffold(
appBar: AppBar(
title: Text('First'),
),
body: RaisedButton(
child: Text('Move to Next Page'),
onPressed: () {
final person = Person('Peter', 20);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondStatefulPage(person: person),
)
);
},
)
);
}
}
class SecondStatefulPage extends StatefulWidget {
final Person person;
SecondStatefulPage({Key key, @required this.person}) : super(key: key);
@OverRide
_SecondStatefulPageState createState() => _SecondStatefulPageState();
}
class _SecondStatefulPageState extends State {
@OverRide
Widget build(BuildContext context) {
print('Second Page build() - ');
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: RaisedButton(
child: Text('이전 페이지로'),
onPressed: () {
Navigator.pop(context);
},
)
);
}
}