当我按goto第二页和第一页按钮后退出应用程序时 然后在堆栈中存在MaterialApp Banner,所以我想删除它,如果好的可以给我其他方式。 我的任务是我要切换页面并要在每个开关中重建“ initState”?
// this is main.dart
import 'package:flutter/material.dart';
import 'first_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: FirstPage(),
);
}
}
// this is first_page.dart
import 'package:flutter/material.dart';
import 'second_page.dart';
class FirstPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return FirstPageState();
}
}
class FirstPageState extends State<FirstPage>{
@override
void initState() {
// TODO: implement initState
super.initState();
debugPrint("im in first page");
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("First page"),
),
body: Center(
child:RaisedButton(
child: Text("Goto Second page")
,onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context){
return SecondPage();
}));
})
),
);
}
}
// this is second_page.dart
import 'package:flutter/material.dart';
import 'first_page.dart';
class SecondPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return SecondPageState();
}
}
class SecondPageState extends State<SecondPage>{
@override
void initState() {
// TODO: implement initState
super.initState();
debugPrint("im in second page");
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Second page"),
),
body: Center(
child:RaisedButton(
child: Text("Goto Second page")
,onPressed: (){
Navigator.pop(context);
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context){
return FirstPage();
}));
})
),
);
}
}
//请检查并提供问题解决方案