如何导航到另一个屏幕

时间:2019-06-05 04:05:37

标签: android flutter dart flutter-navigation

我有一个下一个 RaisedButton ,可以进入下一个名为 DetailOracion 的屏幕。

基于 Flutter 的示例来推送新屏幕,但不起作用。

Caused by: org.apache.spark.api.python.PythonException: Traceback (most recent call last):
  File "/Users/yashphogat/Downloads/spark-2.33-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/worker.py", line 253, in main
    process()
  File "/Users/yashphogat/Downloads/spark-2.33-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/worker.py", line 248, in process
    serializer.dump_stream(func(split_index, iterator), outfile)
  File "/Users/yashphogat/Downloads/spark-2.33-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/serializers.py", line 379, in dump_stream
    vs = list(itertools.islice(iterator, batch))
  File "/Users/yashphogat/Downloads/spark-2.33-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/util.py", line 55, in wrapper
    return f(*args, **kwargs)
  File "/Users/yashphogat/Python_Programs/lib/python3.6/site-packages/pyspark/rdd.py", line 1967, in <lambda>
    <b>flat_map_fn = lambda kv: ((kv[0], x) for x in f(kv[1]))
TypeError: 'int' object is not iterable

我的DetailOracion

  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'),
  );
 }
}

2 个答案:

答案 0 :(得分:1)

使用 MaterialPageRoute 时,您需要从 runApp()

将主类发送到 MaterialApp

解释代码

正确

void main() => runApp(MaterialApp(
  title: 'Oraciones Cristianas',
  home: MyApp(),
));

您向您发送的第一个屏幕信息是 MaterialApp(),可以使用 MaterialPageRoute()

不正确

void main() => runApp(myApp());

如果您只发送没有 MaterialApp()包装器的第一个屏幕,则不起作用

答案 1 :(得分:-1)

在按钮或列周围使用构建器,如以下代码所示:

Builder(
    builder: (context) => RaisedButton(
          onPressed: () {
            Navigator.push(context,
                MaterialPageRoute(
                    builder: (context) => SelectUserType()));
          },
          child: Text('Registrese'),
        ),
  ),