The argument type Set<Map<String, Widget Function(BuildContext)>> can't be assigned to the parameter type 'Map<String, Widget Function(BuildContext)>

Viewed 142

I just started learning flutter and I don't quite understand how to fix this error. I wanted to make my own factory of screens and use them in persistent_bottom_nav_bar package.

The code with the error location (error in the routes field):

class _BottomNavigationBarItemFactory {
  final String iconName;
  final String label;

  _BottomNavigationBarItemFactory(this.iconName, this.label);

  PersistentBottomNavBarItem build(
    int index,
    int currentIndex,
    BottomNavigationBarThemeData theme,
  ) {
    final color = index == currentIndex
        ? theme.selectedItemColor
        : theme.unselectedItemColor;
    return PersistentBottomNavBarItem(
      routeAndNavigatorSettings: RouteAndNavigatorSettings(
        initialRoute: Screens.main,
        routes: {
          MainNavigation.routers
        },
      ),
      title: label,
      icon: Image.asset(
        iconName,
        color: color,
      ),
    );
  }
}

class MainNavigation:

abstract class Screens {
  static const main = "/";
  static const notification = "/notification_screen";
}

class MainNavigation {
  final _screenFactoty = ScreenFactory();
  
  Map<String, WidgetBuilder> get routers => <String, WidgetBuilder>{
        Screens.main: (_) => _screenFactoty.makeMainTabs(),
        Screens.notification: (_) => _screenFactoty.makeNotificationScreen(),
      };

  Route<dynamic>? onGenerateRoute(RouteSettings settings) {
    return null;
  }
}

class ScreenFactory:

class ScreenFactory {
  Widget makeMainTabs() => ChangeNotifierProvider(
    child: MainTabsScreen(),
    create: (_) => MainTabsViewModel(),
    );

  Widget makeNotificationScreen() => const NotificationScreen();
}
1 Answers

Try removing the {} you have around MainNavigation.routers

Related