PersistentBottomNavBar icon indicating copy to clipboard operation
PersistentBottomNavBar copied to clipboard

Could not find a generator for route RouteSettings("/passArguments", Instance of 'ScreenArguments') in the _CustomTabViewState.

Open mtical opened this issue 5 years ago • 18 comments

Seems to be an issue passing arguments over with a Navigator.pushNamed(context, PassArgumentsScreen.routeName, arguments: ScreenArguments('arg1', 'arg2')); when using persistent bottom nav bar.

persistent_bottom_nav_bar: ^2.0.5 Flutter 1.22.0

Code to reproduce:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar/persistent-tab-view.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      onGenerateRoute: (settings) {
        // If you push the PassArguments route
        if (settings.name == PassArgumentsScreen.routeName) {
          // Cast the arguments to the correct type: ScreenArguments.
          final ScreenArguments args = settings.arguments;

          return MaterialPageRoute(
            builder: (context) {
              return PassArgumentsScreen(
                title: args.title,
                message: args.message,
              );
            },
          );
        }
        assert(false, 'Need to implement ${settings.name}');
        return null;
      },
      title: 'Navigation with Arguments',
      home: Home(),
    );
  }
}

class ScreenOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Screen'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              child: Text("Navigate to a named that accepts arguments"),
              onTap: () {
                // When the user taps the button, navigate to a named route
                // and provide the arguments as an optional parameter.
                Navigator.pushNamed(
                  context,
                  PassArgumentsScreen.routeName,
                  arguments: ScreenArguments(
                    'Accept Arguments Screen',
                    'This message is extracted in the onGenerateRoute function.',
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}

// A Widget that accepts the necessary arguments via the constructor.
class PassArgumentsScreen extends StatelessWidget {
  static const routeName = '/passArguments';

  final String title;
  final String message;

  const PassArgumentsScreen({
    Key key,
    @required this.title,
    @required this.message,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Text(message),
      ),
    );
  }
}

class ScreenArguments {
  final String title;
  final String message;

  ScreenArguments(this.title, this.message);
}

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    PersistentTabController _controller = PersistentTabController(initialIndex: 0);

    return PersistentTabView(
      routeName: '/',
      screens: _buildScreens(),
      controller: _controller,
      items: _navBarsItems(),
      confineInSafeArea: true,
      backgroundColor: Colors.black,
      handleAndroidBackButtonPress: true,
      resizeToAvoidBottomInset: true,
      stateManagement: true,
      hideNavigationBarWhenKeyboardShows: true,
      decoration: NavBarDecoration(
        borderRadius: BorderRadius.circular(10.0),
        colorBehindNavBar: Colors.white,
      ),
      popAllScreensOnTapOfSelectedTab: true,
      // Navigation Bar's items animation properties.
      itemAnimationProperties: ItemAnimationProperties(
        duration: Duration(milliseconds: 200),
        curve: Curves.ease,
      ),
      // Screen transition animation on change of selected tab.
      screenTransitionAnimation: ScreenTransitionAnimation(
        animateTabTransition: true,
        curve: Curves.ease,
        duration: Duration(milliseconds: 200),
      ),
      navBarStyle: NavBarStyle.style6,
    );
  }

  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        // rectangle_grid_1x2
        icon: Icon(Icons.search),
        activeColor: CupertinoColors.white,
        inactiveColor: CupertinoColors.systemGrey,
      ),
      PersistentBottomNavBarItem(
        // rectangle_grid_1x2
        icon: Icon(Icons.home),
        activeColor: CupertinoColors.white,
        inactiveColor: CupertinoColors.systemGrey,
      ),
    ];
  }

  List<Widget> _buildScreens() {
    return [
      ScreenOne(),
      PassArgumentsScreen(),
    ];
  }
}

mtical avatar Oct 02 '20 21:10 mtical

I have the same problem

geekhenno avatar Oct 04 '20 14:10 geekhenno

I'll look into it ASAP.

BilalShahid13 avatar Oct 06 '20 02:10 BilalShahid13

@BilalShahid13 can you show us solution for named route?

NitelPhyoe avatar Oct 06 '20 04:10 NitelPhyoe

@NitelPhyoe You can push like you would without the navigation bar i.e. Navigator.pushNamed(context, "routeName");.

BilalShahid13 avatar Oct 09 '20 04:10 BilalShahid13

@NitelPhyoe You can push like you would without the navigation bar i.e. Navigator.pushNamed(context, "routeName");.

I tried the same but it won't work for me.

Could not find a generator for route RouteSettings("/subCategory", null) in the _CustomTabViewState. Generators for routes are searched for in the following order:

  1. For the "/" route, the "builder" property, if non-null, is used.
  2. Otherwise, the "routes" table is used, if it has an entry for the route.
  3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "builder" and "routes".
  4. Finally if all else fails onUnknownRoute is called. Unfortunately, onUnknownRoute was not set.

dhalloop7 avatar Nov 18 '20 12:11 dhalloop7

Are you sure the new screen is below in level of widget/screen hierarchy than the current screen? I tried pushing it but I faced no such issues.

BilalShahid13 avatar Dec 06 '20 16:12 BilalShahid13

I was able to successfully reproduce the problem. It is now fixed in version 3.1.0 but you will have to define your routes in the argument routeAndNavigatorSettings for it to work.

BilalShahid13 avatar Dec 06 '20 17:12 BilalShahid13

I was able to successfully reproduce the problem. It is now fixed in version 3.1.0 but you will have to define your routes in the argument routeAndNavigatorSettings for it to work.

@BilalShahid13 , Okay.. Now i can successfully navigate with named route but now It's creating a stack of widget when i navigate back with named route

iamnabink avatar Jan 08 '21 10:01 iamnabink

Can you try again using the latest version 4.0.0? You probably will have to pop the screens before navigating again with named route.

BilalShahid13 avatar Mar 22 '21 12:03 BilalShahid13

When Navigator.pushNamed(context, "routeName"); is used, It always pushes new screen with NavBar. Any way to to hide it when using Navigator.pushNamed(context, "routeName"); ?

AhmadRehan71 avatar Jun 15 '21 18:06 AhmadRehan71

Dear all I am using persistent_bottom_nav_bar: ^4.0.2 and I am still facing the same issue... every time I am trying to use pushnamed it creates this error. Any idea how to fix it.

HussainObn avatar Aug 30 '21 17:08 HussainObn

+1

kevinkooyizen avatar Sep 07 '21 10:09 kevinkooyizen

@HussainObn set your routes in the argument [routeAndNavigatorSettings] in [PersistentBottomNavBarItem]

aonpongsiri avatar Sep 09 '21 04:09 aonpongsiri

@aonpongsiri your solution doesnt works for PersistentTabView.custom

maazkhan1998 avatar Nov 10 '21 06:11 maazkhan1998

+1 I am trying this

              Navigator.pushNamedAndRemoveUntil(
                context,
                Screens.auth,
                (_) => false,
              );

but I am getting this :

[log] Could not find a generator for route RouteSettings("auth", null) in the _CustomTabViewState.
      Generators for routes are searched for in the following order:
       1. For the "/" route, the "builder" property, if non-null, is used.
       2. Otherwise, the "routes" table is used, if it has an entry for the route.
       3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "builder" and "routes".
       4. Finally if all else fails onUnknownRoute is called.
      Unfortunately, onUnknownRoute was not set.

& I have also set onUnknownRoute on my MaterialApp.

onUnknownRoute: (settings) { return MaterialPageRoute(builder: (context) => const Auth()); },

nehal076 avatar Aug 30 '23 07:08 nehal076

@nehal076

You need to define the route like so:

PersistentBottomNavBarItem(
        icon: const Icon(Icons.settings),
        title: "Settings",
        activeColorPrimary: Colours.darkyBlue,
        inactiveColorPrimary: Colors.grey,
        routeAndNavigatorSettings: RouteAndNavigatorSettings(
          initialRoute: "/",
          routes: {
            "/auth": (final context) => const AuthApp(),
          },
        ),
),

Tarhex avatar Jan 01 '24 22:01 Tarhex

@Tarhex

i did this solution , but bottom nav bar stayed in the screen and i don't want that

how i can resolve this ?

abdocrowinho avatar Feb 05 '24 13:02 abdocrowinho

@Tarhex

i did this solution , but bottom nav bar stayed in the screen and i don't want that

how i can resolve this ?

What do you want to achieve? Navigate to another page without the BottomNavBar?

Tarhex avatar Feb 05 '24 14:02 Tarhex