Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p204 Statefull 클래스의 동작이 책에 설명되어 있는것과 다르게 동작합니다 #2

Closed
neighborpil opened this issue Jul 23, 2020 · 3 comments

Comments

@neighborpil
Copy link

현재 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);
},
)
);
}
}

@junsuk5
Copy link
Owner

junsuk5 commented Jul 23, 2020

저도 방금 확인해 보니 책 내용과 다르게 FirstPage가 다시 그려지지 않았습니다.
그래서 책 집필 당시 버전(1.12.13)으로 다운그레이드 해서 확인 해 보니 책 내용대로 이전 화면도 다시 그려집니다.
현재 버전이 1.17 버전대라서 그 사이에 엄청나게 업데이트되면서 불필요한 동작이 개선된 것 같습니다.
해당 내용에 대해 깃헙에 공지하고 개정시 해당 절은 삭제 조치해야겠네요.
제보 감사드립니다.

@junsuk5 junsuk5 closed this as completed Jul 23, 2020
@junsuk5
Copy link
Owner

junsuk5 commented Jul 23, 2020

확인하시고 이슈 닫아주세요

@junsuk5 junsuk5 reopened this Jul 23, 2020
@neighborpil
Copy link
Author

확인하였습니다. 감사합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants