如何导航到另一个屏幕
How navigate to another screen
我有下一个 RaisedButton 去下一个名为 DetailOracion 的屏幕。
基于 Flutter 的示例推送新屏幕但确实有效。
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Oraciones Cristianas'),
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => DetailOracion()));
},
child: Text('Hello Wolrd'),
)
],
),
)),
),
);
}
我的详细信息
class DetailOracion extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hola'),
),
body: Text('Segunda Pantalla'),
);
}
}
错误消息是下一个
I/flutter ( 3441): The following assertion was thrown while handling a gesture:
I/flutter ( 3441): Navigator operation requested with a context that does not include a Navigator.
I/flutter ( 3441): The context used to push or pop routes from the Navigator must be that of a widget that is a
I/flutter ( 3441): descendant of a Navigator widget.
在您的按钮或列周围使用生成器,如下面的代码所示:
Builder(
builder: (context) => RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => SelectUserType()));
},
child: Text('Registrese'),
),
),
当使用 MaterialPageRoute 时,您需要从 runApp 发送 MaterialApp 内的主要 class ()
用代码解释
正确
void main() => runApp(MaterialApp(
title: 'Oraciones Cristianas',
home: MyApp(),
));
您首先发送 MaterialApp() 的屏幕插入,可以使用 MaterialPageRoute()
不正确
void main() => runApp(myApp());
如果您只是在没有 MaterialApp() 的情况下发送您的第一个屏幕,则包装器不起作用
我有下一个 RaisedButton 去下一个名为 DetailOracion 的屏幕。
基于 Flutter 的示例推送新屏幕但确实有效。
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Oraciones Cristianas'),
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => DetailOracion()));
},
child: Text('Hello Wolrd'),
)
],
),
)),
),
);
}
我的详细信息
class DetailOracion extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hola'),
),
body: Text('Segunda Pantalla'),
);
}
}
错误消息是下一个
I/flutter ( 3441): The following assertion was thrown while handling a gesture:
I/flutter ( 3441): Navigator operation requested with a context that does not include a Navigator.
I/flutter ( 3441): The context used to push or pop routes from the Navigator must be that of a widget that is a
I/flutter ( 3441): descendant of a Navigator widget.
在您的按钮或列周围使用生成器,如下面的代码所示:
Builder(
builder: (context) => RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => SelectUserType()));
},
child: Text('Registrese'),
),
),
当使用 MaterialPageRoute 时,您需要从 runApp 发送 MaterialApp 内的主要 class ()
用代码解释
正确
void main() => runApp(MaterialApp(
title: 'Oraciones Cristianas',
home: MyApp(),
));
您首先发送 MaterialApp() 的屏幕插入,可以使用 MaterialPageRoute()
不正确
void main() => runApp(myApp());
如果您只是在没有 MaterialApp() 的情况下发送您的第一个屏幕,则包装器不起作用