我正在学习使用颤振并决定处理路线(路线)。面临以下问题:
我有几个屏幕:Screen_1,Screen_2,Screen_3。从Screen_1我去Screen_2,从那里到Screen_3,从那里回到Screen_1。现在,当我按下“返回”键时,它会从 Screen_1 返回到Screen_3 ,然后返回到Screen_2 ,依此类推。问题是如何做到这一点,如果我从Screen_3返回到Screen_1,那么当我按下“返回”键时,我无法返回到Screen_3?以及如何去掉这个箭头“返回”的显示在屏幕顶部?
示例: 视频
动图:
路线代码:
import 'package:flutter/material.dart';
import 'package:quest/Screens/Endings/endings.dart';
import 'package:quest/Screens/NewGame/levelChoice.dart';
import 'package:quest/Screens/NewGame/newGame.dart';
import 'package:quest/Screens/Settings/settings.dart';
import 'package:quest/main.dart';
final routes = {
'/': (BuildContext context) => new MyApp(),
'/Endings': (BuildContext context) => new EndingsScreen(),
'/LevelChoice': (BuildContext context) => new LevelChoiceScreen(),
'/NewGame': (BuildContext context) => new NewGameScreen(),
'/Settings': (BuildContext context) => new SettingsScreen()
};
main.dart 代码
import 'package:flutter/material.dart';
import 'package:quest/Config/Routes.dart';
import 'package:quest/Config/UiData.dart';
void main() {
runApp(MaterialApp(
title: UiData.AppName,
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: routes,
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
UiData.deviceSize = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text(UiData.AppName + " " + UiData.AppVersion),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: UiData.deviceSize.height / 5,
width: UiData.deviceSize.width,
child: Center(
child: Text(UiData.AppName,
style: new TextStyle(
fontSize: 100.0,
fontFamily: 'MainFonts',
color: Colors.black,
),
),
)
),
Container(
height: UiData.deviceSize.height / 10,
width: UiData.deviceSize.width / 2,
padding: EdgeInsets.all(5.0),
child: MaterialButton(
height: UiData.deviceSize.height / 10,
minWidth: UiData.deviceSize.width / 2,
color: Theme.of(context).primaryColor,
textColor: Colors.white,
child: new Text(
"Новая игра",
style: new TextStyle(
fontSize: 25.0,
fontFamily: 'ButtonFonts',
color: Colors.yellow,
),
),
onPressed: () {
Navigator.pushNamed(context, '/LevelChoice');
},
splashColor: Colors.redAccent,
),
),
],
),
),
);
}
}
等级选择代码:
import 'package:flutter/material.dart';
import 'package:quest/Config/UiData.dart';
class LevelChoiceScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Выбор уровня"),
),
body: Center(
child: ListView(
children: <Widget>[
Container(
height: UiData.deviceSize.height / 10,
width: UiData.deviceSize.width / 2,
padding: EdgeInsets.all(5.0),
child: MaterialButton(
height: UiData.deviceSize.height / 10,
minWidth: UiData.deviceSize.width / 2,
color: Theme.of(context).primaryColor,
textColor: Colors.white,
child: new Text(
"Акт 1",
style: new TextStyle(
fontSize: 25.0,
fontFamily: 'ButtonFonts',
color: Colors.yellow,
),
),
onPressed: () {
Navigator.pushNamed(context, '/NewGame');
},
splashColor: Colors.redAccent,
),
),
RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
],
),
),
);
}
}
新游戏代码:
import 'package:flutter/material.dart';
class NewGameScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Новая игра"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pushNamed(context, '/');
},
child: Text('Go back!'),
),
),
);
}
}