我的应用程序有一个特定的屏幕,根据状态,该屏幕可以具有一个或三个FloatingActionButton。从该屏幕回到主屏幕,应显示一个FloatingActionButton。回溯是指使用手机上的“后退”按钮或单击一个调用Navigator.pop(context)的按钮(这是三个按钮之一)。
如果此屏幕处于带有一个FloatingActionButton的状态,并且将使用电话的后退按钮,则将正确加载主屏幕并显示FloatingActionButton。但是,如果屏幕处于其他状态,并且将使用后退按钮或Navigator.pop(context),则将在没有FloatingActionButton的情况下构建主屏幕。
//function of the second-screen
void exit() {
controllerWhite.dispose();
controllerBlack.dispose();
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
Navigator.pop(context);
}
//home-screen
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Consumer<AppState>(builder: (context, appState, child) {
return Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(
icon: Icon(
Icons.settings,
color: appState.getColorTheme()['black'],
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingsScreen(
)),
);
},
)
],
backgroundColor: appState.getColorTheme()['background'],
title: Text(widget.title,
style: TextStyle(
fontSize: 20, color: appState.getColorTheme()['accent'])),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ScrollableGamesGrid(
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
//FloatingActionButton which is either build or not build
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (_) {
return NewGame(
);
});
},
label: Text('Add custom game'),
icon: Icon(Icons.add),
backgroundColor: appState.getColorTheme()['accent'],
),
);
});
}
}
这不包括第二个屏幕的整个代码,如果您认为有必要回答这个问题,请告诉我。