Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 找不到处于“WidgetsAppState”状态的路由路由设置(“SecondScreens”,null)的生成器_Flutter - Fatal编程技术网

Flutter 找不到处于“WidgetsAppState”状态的路由路由设置(“SecondScreens”,null)的生成器

Flutter 找不到处于“WidgetsAppState”状态的路由路由设置(“SecondScreens”,null)的生成器,flutter,Flutter,我试图通过multiple FloatingActionButton移动到第二个页面,但在按下任何FloatingActionButton弹出窗口后,我面临以下问题:在_WidgetsAppState中找不到路由设置的生成器(“SecondScreens”,null) 问题在哪里?如果有人知道这对我有帮助,该如何解决 完整代码 import 'package:flutter/material.dart'; import 'dart:math' as math; void main() {

我试图通过multiple FloatingActionButton移动到第二个页面,但在按下任何FloatingActionButton弹出窗口后,我面临以下问题:在_WidgetsAppState中找不到路由设置的生成器(“SecondScreens”,null)

问题在哪里?如果有人知道这对我有帮助,该如何解决

完整代码


import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  AnimationController _controller;

  static const List<IconData> icons = const [
    Icons.sms,
    Icons.mail,
    Icons.phone
  ];

  @override
  void initState() {
    _controller = new AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 500),
    );
  }

  Widget build(BuildContext context) {
    Color backgroundColor = Theme.of(context).cardColor;
    Color foregroundColor = Theme.of(context).accentColor;
    return new Scaffold(
      appBar: new AppBar(title: new Text('Speed Dial Example')),
      floatingActionButton: new Column(
        mainAxisSize: MainAxisSize.min,
        children: new List.generate(icons.length, (int index) {
          Widget child = new Container(
            height: 70.0,
            width: 56.0,
            alignment: FractionalOffset.topCenter,
            child: new ScaleTransition(
              scale: new CurvedAnimation(
                parent: _controller,
                curve: new Interval(0.0, 1.0 - index / icons.length / 2.0,
                    curve: Curves.easeOut),
              ),
              child:
              fabWidget(context, index, backgroundColor, foregroundColor),
            ),
          );
          return child;
        }).toList()
          ..add(
            new FloatingActionButton(
              heroTag: null,
              child: new AnimatedBuilder(
                animation: _controller,
                builder: (BuildContext context, Widget child) {
                  return new Transform(
                    transform: new Matrix4.rotationZ(
                        _controller.value * 0.5 * math.pi),
                    alignment: FractionalOffset.center,
                    child: new Icon(
                        _controller.isDismissed ? Icons.share : Icons.close),
                  );
                },
              ),
              onPressed: () {
                if (_controller.isDismissed) {
                  _controller.forward();
                } else {
                  _controller.reverse();
                }
              },
            ),
          ),
      ),
    );
  }

  Widget fabWidget(BuildContext context, int index, Color backgroundColor,
      Color foregroundColor) {
    String route = "";
    switch (index) {
      case 0:
        route = "SecondScreens";
        break;
      case 1:
        route = "thirdScreen";
        break;
      default:
    }

    return FloatingActionButton(
      heroTag: null,
      backgroundColor: backgroundColor,
      mini: true,
      child: new Icon(icons[index], color: foregroundColor),
      onPressed: () {
        Navigator.pushNamed(context, route);
      },
    );
  }
}



进口“包装:颤振/材料.省道”;
导入'dart:math'作为数学;
void main(){
runApp(新的MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
主页:新建MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
@凌驾
State createState()=>新建MyHomePageState();
}
类MyHomePageState使用TickerProviderStateMixin扩展状态{
动画控制器_控制器;
静态常量列表图标=常量[
Icons.sms,
Icons.mail,
图标.手机
];
@凌驾
void initState(){
_控制器=新的AnimationController(
vsync:这个,,
持续时间:常量持续时间(毫秒:500),
);
}
小部件构建(构建上下文){
Color backgroundColor=主题.of(context).cardColor;
Color-foregroundColor=Theme.of(context).accentColor;
归还新脚手架(
appBar:new appBar(标题:新文本(“快速拨号示例”),
floatingActionButton:新列(
mainAxisSize:mainAxisSize.min,
子项:新建列表。生成(icons.length,(int索引){
Widget子组件=新容器(
身高:70.0,
宽度:56.0,
对齐:分馏Loffset.topCenter,
子:新的ScaleTransition(
比例:新曲线动画(
父节点:_控制器,
曲线:新的间隔(0.0,1.0-索引/icons.length/2.0,
曲线:曲线。easeOut),
),
儿童:
fabWidget(上下文、索引、背景色、前景色),
),
);
返回儿童;
})托利斯先生()
……加上(
新浮动操作按钮(
heroTag:null,
子对象:新的动画生成器(
动画:_控制器,
生成器:(BuildContext上下文,小部件子项){
返回新变换(
变换:新矩阵x4.rotationZ(
_controller.value*0.5*math.pi),
对齐:分馏loffset.center,
孩子:新图标(
_controller.isDismissed?Icons.share:Icons.close),
);
},
),
已按下:(){
如果(_controller.isdissed){
_controller.forward();
}否则{
_controller.reverse();
}
},
),
),
),
);
}
Widget fabWidget(构建上下文上下文、int索引、颜色背景色、,
颜色(背景色){
字符串route=“”;
开关(索引){
案例0:
route=“SecondScreens”;
打破
案例1:
route=“第三屏幕”;
打破
违约:
}
返回浮动操作按钮(
heroTag:null,
背景色:背景色,
米尼:是的,
子项:新图标(图标[索引],颜色:foregroundColor),
已按下:(){
Navigator.pushNamed(上下文、路由);
},
);
}
}

您使用的是
Navigator.pushNamed
,它要求在App routes属性中定义作为第二个参数的路由,如下所示:

MaterialApp(
  // Start the app with the "/" named route. In this case, the app starts
  // on the FirstScreen widget.
  initialRoute: '/',
  routes: {
    // When navigating to the "/" route, build the FirstScreen widget.
    '/': (context) => FirstScreen(),
    // When navigating to the "/second" route, build the SecondScreen widget.
    '/second': (context) => SecondScreen(),
  },
);
每个路由都定义为MapEntry,第一部分是路由名称,因此您称为“routeName”的参数和第二部分是一个小部件构造函数,它是您希望该路由对应的页面

在您的情况下,您可以添加如下内容:

MaterialApp(
  // Start the app with the "/" named route. In this case, the app starts
  // on the FirstScreen widget.
  initialRoute: '/',
  routes: {
    // When navigating to the "/" route, build the FirstScreen widget.
    '/': (context) => MyHomePage(),
    // When navigating to the "/second" route, build the SecondScreens widget.
    '/second': (context) => SecondScreens(),
    // When navigating to the "/third" route, build the thirdScreens widget.
    '/third': (context) => SecondScreens(),
    ///All the other screens in your app.

  },
);
然后您的fabWidget功能可以更改为:

Widget fabWidget(BuildContext context, int index, Color backgroundColor,
      Color foregroundColor) {
    String route = "";
    switch (index) {
      case 0:
        route = "/second";
        break;
      case 1:
        route = "/third";
        break;
      default:
    }

    return FloatingActionButton(
      heroTag: null,
      backgroundColor: backgroundColor,
      mini: true,
      child: new Icon(icons[index], color: foregroundColor),
      onPressed: () {
        Navigator.pushNamed(context, route);
      },
    );
  }