티스토리 뷰
반응형
마지막 페이지를 파일에 데이터로 저장한다.
프로그램 실행시, Build가 끝나면, 마지막 페이지 정보를 확인하고, 해당 페이지를 연다.
페이지 여는 방법은 Navigator.push를 사용한다.
class Page1 extends StatefulWidget {
...
BuildContext ?context_now=null;
void Navigator_push_Page(Widget page){//page=Page1()
if(context_now!=null) {
Navigator.push(
context_now!, MaterialPageRoute(builder: (context_now) => page));
}
}
void open_Page1()
{
LastPage="Page1";
Navigator_push_Page(Page1());
}
메인화면 생성이 끝나고 바로 페이지를 열면, 뒤로가기가 안되는 문제가 있어,
타이머에서 처리한다.
Future<void> AfterBuild() async {
// this code will get executed after the build method
// because of the way async functions are scheduled
if(Open_LastPage_sec>0)
{
Open_LastPage_sec=1;
}
}
@override
Widget build(BuildContext context) {
context_now=context;
AfterBuild();
...
방법은 여러가지가 있다.
알아서 쓰세요.
화면생성하고 뭔가를 하기위해, 위처럼 복잡한 여러가지 과정을 거쳐야 한다.
이유는 Flutter Dart가 비동기이기때문이다.
그런데, 비동기를 사용하여 이것도 어느정도 해결된다.
Dart는 마지막페이지 하나 띄우는데, 이렇게까지 해야하나 싶은...
참 남감한 언어이다. 꼼수에 꼼수...(내가 잘 몰라서 그런거겠지?)
(누가 만들었는지....)
반응형
'Flutter' 카테고리의 다른 글
Flutter - 문제점? (0) | 2022.09.10 |
---|---|
Flutter - 우측에 앱 종료 x 버튼 추가하기 (0) | 2022.09.10 |
Flutter - enum형 (0) | 2022.09.06 |
flutter combobox 어렵네... (0) | 2022.08.26 |
flutter i폰 앱 디버깅 - Could not build the precompiled application for the device. (0) | 2022.06.27 |