Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mtical opened this issue Oct 2, 2020 · 18 comments

Comments

@mtical
Copy link

mtical commented Oct 2, 2020

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(),
    ];
  }
}
@geekhenno
Copy link

I have the same problem

@BilalShahid13
Copy link
Owner

I'll look into it ASAP.

@NitelPhyoe
Copy link

@BilalShahid13 can you show us solution for named route?

@BilalShahid13
Copy link
Owner

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

@dhalloop7
Copy link

@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.

@BilalShahid13
Copy link
Owner

BilalShahid13 commented Dec 6, 2020

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
Copy link
Owner

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 BilalShahid13 pinned this issue Dec 6, 2020
@iamnabink
Copy link

iamnabink commented Jan 8, 2021

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

@BilalShahid13
Copy link
Owner

BilalShahid13 commented Mar 22, 2021

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.

@AhmadRehan71
Copy link

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"); ?

@HussainObn
Copy link

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.

@kevinkooyizen
Copy link

+1

@aonpongsiri
Copy link

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

@maazkhan1998
Copy link

@aonpongsiri your solution doesnt works for PersistentTabView.custom

@nehal076
Copy link

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

@Tarhex
Copy link

Tarhex commented Jan 1, 2024

@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(),
          },
        ),
),

@abdocrowinho
Copy link

@Tarhex

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

how i can resolve this ?

@Tarhex
Copy link

Tarhex commented Feb 5, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests