颤振“上下文” Navigatior.pushedNamed生成器RouteSettings

时间:2020-08-06 12:08:31

标签: flutter routes navigator

我的Navigator.pushNamed不再起作用,因为我将BottomNavigationBar重构为一个新类。 setState()工作正常,因此我强烈认为context存在问题。 BottomNavigationBar出现在应用程序中,但不会再将我带到下一页。我现在要花几个小时才能解决这个问题……

我得到的错误是: 在_WidgetsAppState中找不到路由RouteSettings(“ ...”,null)的生成器。

NewBottomNavigationBar

class NewBottomNavigationBar extends StatefulWidget {
  @override
  _NewBottomNavigationBarState createState() => _NewBottomNavigationBarState();
}

class _NewBottomNavigationBarState extends State<NewBottomNavigationBar> {
  int _selectedTab = 0;
  final _selectedTabList = [
    TheSlateScreen.id,
    Search.id,
    LoginScreen.id,
  ];
  @override
  Widget build(BuildContext context) {

return BottomNavigationBar(
    currentIndex: _selectedTab,
    onTap: (int index) {
      setState(() {
        _selectedTab = index;
      });

      Navigator.pushNamed(
        context,
        _selectedTabList[_selectedTab].toString(),
      );
    },
    unselectedItemColor: kSlate,
    items: const <BottomNavigationBarItem>[

......

我在其中使用NewBottomNavigation()的类

class TheSlateScreen extends StatefulWidget {
      static const String id = 'theslate_screen';
      @override
      _TheSlateScreenState createState() => _TheSlateScreenState();
    }
    
    class _TheSlateScreenState extends State<TheSlateScreen> {   



 @override
      Widget build(BuildContext context) {
        screenWidth = MediaQuery.of(context).size.width;
        screenHeight = MediaQuery.of(context).size.height;

return MaterialApp(
 home: Scaffold(
    bottomNavigationBar: NewBottomNavigationBar(),
    appBar: AppBar(
      leading: null,
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.close),

.....

我的main.dart中的路线

    class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (context) => SlateTasks(),
        child: MaterialApp(
          initialRoute: LoginScreen.id,
          routes: {
            LoginScreen.id: (context) => LoginScreen(),
            RegistrationScreen.id: (context) => RegistrationScreen(),
            TheSlateScreen.id: (context) => TheSlateScreen(),
            ResetPasswordScreen.id: (context) => ResetPasswordScreen(),
            Search.id: (context) => Search(),
          },
        ));

0 个答案:

没有答案