![](/img/trans.png)
[英]How can I show full screen dialog or navigate to other screen when I click a Layout function?
[英]How to create full screen dialog in flutter when I am using root names to Navigate?
這是使用rootName的示例代碼,但是在這里,我無法使用MaterialPageRoute來獲取fullScreenDialog屬性。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => MyHomePage(),
'/under-development': (context) => UnderDevelopment(),
'/profile1': (context) => Profile1()
},
title: appName,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: primaryColor,
accentColor: secondaryColor,
fontFamily: 'Poppins'),
);
}
}
航海家
onTap: () {
Navigator.pushNamed(context, '/profile1');
},
您可以在Material App中使用類似的方法。 希望對您有所幫助。
onGenerateRoute: (RouteSettings settings) {
List<String> pathElements = settings.name.split("/");
if (pathElements[0] != "") return null;
switch (pathElements[1]) {
case "home":
String userID = pathElements[2];
return MaterialPageRoute(
builder: (context) => ReportsPage(
userID: userID,
),fullscreenDialog: true);
}
},
new MaterialApp(
title: 'Named Routes Demo',
theme: ThemeData(
primarySwatch: Colors.green),
initialRoute: '/',
onGenerateRoute: (RouteSettings settings) {
List<String> pathElements = settings.name.split("/");
if (pathElements[0] != "") return null;
switch (pathElements[1]) {
case "":
return MaterialPageRoute(
builder: (context) => FirstScreen());
case "second":
return MaterialPageRoute(
builder: (context) => SecondScreen(), fullscreenDialog: true);
case "third":
return MaterialPageRoute(
builder: (context) => ThirdScreen(), fullscreenDialog: true);
}
},
)
導航按鈕
onTap: () {
Navigator.pushNamed(context, '/second');
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.