在_CustomNavigatorState中找不到路由RouteSettings(“ / pomodoro”,null)的生成器

时间:2020-03-18 16:29:38

标签: flutter

当我尝试在Flutter应用程序中从一个视图导航到另一个视图时,出现异常。 我已经尝试了许多不同的操作,例如创建新的RoutingGenerator等,但是实际上对我有用的是使用Navigator.push(context, new MaterialPageRoute(builder: (context) =>new MyHomePage()));,但我想改用namedRoutes。

3)手势捕获到异常

在_CustomNavigatorState中找不到路由RouteSettings(“ / pomodoro”,null)的生成器。

我的main.dart:

import 'package:device_simulator/device_simulator.dart';
import 'package:flutter/material.dart';
import 'package:focus/ui/views/home/home_view.dart';
import 'package:focus/ui/views/pomodoro/pomodoro_view.dart';
import 'package:focus/utils/route_generator.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    const bool debugEnableDeviceSimulator = true;

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),

      // Initially display FirstPage
      initialRoute: HomeView.routeName,
      routes: <String, WidgetBuilder>{
        // Code below means:
        // If this is the route, take me this to that particular place
        HomeView.routeName:(context) =>  DeviceSimulator(
            brightness: Brightness.dark,
            enable: debugEnableDeviceSimulator,
            child: HomeView()
        ),

        PomodoroView.routeName:(context) => PomodoroView()
      },

      /*
      routes: {
        // When navigating to the "/" route, build the FirstScreen widget.
        '/': (context) => DeviceSimulator(
            brightness: Brightness.dark,
            enable: debugEnableDeviceSimulator,
            child: HomeView()
        ),

        // When navigating to the "/second" route, build the SecondScreen widget.
        '/pomodoro': (context) => PomodoroView(),
      },
      */

    );
  }
}

我的NavigationBar():

import 'package:flutter/material.dart';
import 'package:focus/main.dart';
import 'package:focus/ui/views/home/home_view.dart';
import 'package:focus/ui/views/pomodoro/pomodoro_view.dart';
import 'package:focus/utils/colors.dart';
import 'package:focus/utils/get_size_of.dart';
import 'package:focus/utils/route_generator.dart';
import 'package:focus/utils/ui_utils.dart';

class $BottomNavigationBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    GetSizeOf getSizeOf = new GetSizeOf();
    $Colors $colors = new $Colors();

    String actualPage;



    double iconNavigationSize = getSizeOf.iconNavigationSize(context);
    double textNavigationSize = getSizeOf.textNavigationSize(context);

    print("iconNavigationSize: ${iconNavigationSize}");
    print("textNavigationSize: ${textNavigationSize}");
    print("2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2");

    return BottomNavigationBar(

        onTap: (int index){
          switch(index){
            case 0:
              actualPage = '/';
              return Navigator.pushNamed(context, HomeView.routeName);

            case 1:
              actualPage = 'pomodoro';
              return Navigator.pushNamed(context, PomodoroView.routeName);
          };

          return null;
        },

        elevation: 18,
        backgroundColor: Colors.white,
        type: BottomNavigationBarType.fixed,
        selectedIconTheme: IconThemeData(color: Colors.purple),
        unselectedIconTheme: IconThemeData(color: Color.fromRGBO(112, 112, 112, 1)),
        selectedItemColor: Colors.purple,
        unselectedItemColor: $colors.black60(),
        selectedFontSize: textNavigationSize,
        unselectedFontSize: textNavigationSize,
        showSelectedLabels: true,
        showUnselectedLabels: true,
        iconSize: iconNavigationSize,

        items: [

          BottomNavigationBarItem(
            icon: new Icon(Icons.home, semanticLabel: "home"),
            title: new Text('Home'),
          ),
          BottomNavigationBarItem(

            icon: new Icon(Icons.timer, semanticLabel: "pomodoro"),
            title: new Text('Pomodoro'),
          ),
          BottomNavigationBarItem(
            icon: new Icon(Icons.done_all, semanticLabel: "to do"),
            title: new Text('Todo'),
          ),
          BottomNavigationBarItem(
            icon: new Icon(Icons.calendar_today, semanticLabel: "calendar"),
            title: new Text('Calendar'),
          )
        ]);
  }
}

0 个答案:

没有答案