1
CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.favorite),
            label: '',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.shopping_cart),
            label: '',
          ),
        ],
      ),
      tabBuilder: (context, index) {
         switch (index) {
          case 0:
            return CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: Categories(), );
            });
           case 1:
            return CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: FavPage(), );
            }); 
            case 2:
            return CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: Cart(), );
            }); 
            default:
            return CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: Categories(), );
            });             
        }
      }, 
    ); 

error message:

Could not find a generator for route RouteSettings("/categoryDetails", GzE5usW4fApu38pjA) in the_CupertinoTabViewState.

when I click on a category in the "Categories" screen it has to navigate to "CategoryDetails" screen

James Z
  • 12,209
  • 10
  • 24
  • 44
Ayz
  • 181
  • 1
  • 9
  • did you define this "/categoryDetails" route in MaterialApp's routes list? – eamirho3ein Aug 01 '22 at 19:11
  • `return MaterialApp( title: 'Flutter Demo', initialRoute: '/', routes: { '/': (context) => const SplashScreen(), '/categories': (context) => const CustomBottomNB(), '/categoryDetails' :(context) => const CategoryDetails(), '/productdetail': (context) => const Product(), }, );` – Ayz Aug 01 '22 at 19:46
  • that's how I defined /categoryDetails – Ayz Aug 01 '22 at 19:49
  • and how did you navigate to /categoryDetails? – eamirho3ein Aug 02 '22 at 13:04
  • when I am in "categories" screen, I can navigate to "categoryDetails". – Ayz Aug 02 '22 at 13:41
  • instead of navigate with push name try this: Navigator.push(context, new MaterialPageRoute( builder: (context) => new CategoryDetails()) ); – eamirho3ein Aug 02 '22 at 15:17
  • No dear, I have to use pushNamed because I need to pass the argument (id of category) in the navigation. – Ayz Aug 06 '22 at 14:37

2 Answers2

0

This should fix it

CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.favorite),
            label: '',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.shopping_cart),
            label: '',
          ),
        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        assert(index >= 0 && index <= 2);
         switch (index) {
          case 0:
            return CupertinoTabView(
              builder: (BuildContext context) => Categories(),,
            );
            break;
          
           case 1:
            return CupertinoTabView(
              builder: (BuildContext context) => FavPage(),
            );
            break;
          
            case 2:
            return CupertinoTabView(
              builder: (BuildContext context) => Cart(),
            );
            break;
          }
             return CupertinoTabView(
          builder: (BuildContext context) => Categories(),
        );             
        }
      }, 
    ); 

Saheed
  • 301
  • 1
  • 2
  • 11
0

Use as routes or onGenererateRoutes according to your requirements in TabViewState of CuptinoTabBar.

Something like this...

return CupertinoTabView(
      routes: appRoutes,
//or
      onGenerateRoutes: ...,