Dart 加载应用程序时,默认路由(';/';)是否会添加到导航器堆栈
例如:Dart 加载应用程序时,默认路由(';/';)是否会添加到导航器堆栈,dart,flutter,Dart,Flutter,例如: import 'package:flutter/material.dart'; void main() => runApp(MaterialApp(home: MyApp(),)); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Rais
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: MyApp(),));
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () => Navigator.pop(context),
child: Text('Go Back'),
),
),
);
}
}
上述示例的屏幕截图:
我知道我可以使用Navigator.canPop(context)
停止这种行为
我的简单问题是,当应用程序启动时只有一个页面,默认路径“/”
会添加到Navigator
列表中吗
如果默认路由推送到Navigator
堆栈(如上图所示),当按下返回时,它是否会从Navigator
堆栈弹出(在上例中)?阅读:
MaterialApp是最简单的设置方式。材料应用
home成为导航器堆栈底部的路线。它是
应用程序启动时看到的内容
请阅读以下内联评论:
是的,当将小部件添加到home
属性时,它将添加到Navigator
堆栈中,这意味着当在该页面中调用pop
时,将从Navigator
堆栈中删除/pop默认路由
注意:根据,不要尝试pop
初始路线/页面(默认路线)
/// The widget for the default route of the app ([Navigator.defaultRouteName],
/// which is `/`).
///
/// This is the route that is displayed first when the application is started
/// normally, unless [initialRoute] is specified. It's also the route that's
/// displayed if the [initialRoute] can't be displayed.
///
/// To be able to directly call [Theme.of], [MediaQuery.of], etc, in the code
/// that sets the [home] argument in the constructor, you can use a [Builder]
/// widget to get a [BuildContext].
///
/// If [home] is specified, then [routes] must not include an entry for `/`,
/// as [home] takes its place.
///
/// The [Navigator] is only built if routes are provided (either via [home],
/// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not,
/// [builder] must not be null.
///
/// The difference between using [home] and using [builder] is that the [home]
/// subtree is inserted into the application below a [Navigator] (and thus
/// below an [Overlay], which [Navigator] uses). With [home], therefore,
/// dialog boxes will work automatically, [Tooltip]s will work, the [routes]
/// table will be used, and APIs such as [Navigator.push] and [Navigator.pop]
/// will work as expected. In contrast, the widget returned from [builder] is
/// inserted _above_ the [MaterialApp]'s [Navigator] (if any).
final Widget home;