GIfatahTH / states_rebuilder

a simple yet powerful state management technique for Flutter
494 stars 56 forks source link

"Null check operator used on a null value" when using toReplacement #260

Closed Reprevise closed 2 years ago

Reprevise commented 2 years ago

I'm trying to setup a bottom navigation bar with named routing and custom transitions but when I use toReplacement on a RouteWidget I get the following exception:

Null check operator used on a null value

The line that's throwing the error is (router_delegate:564, package version: 5.2.0):

RouterObjects.injectedNavigator!.routeData = _lastLeafConfiguration!.rData!;

_lastLeafConfiguration seems to be the variable that's null.

Minimum reproducable sample ```dart Widget _fadeTransition( BuildContext context, Animation animation, Animation secondaryAnimation, Widget child, ) { return FadeTransition( opacity: animation, child: child, ); } final navigator = RM.injectNavigator( builder: (_) => const WrapperScreen(), transitionDuration: 150.milliseconds, routes: { '/': (data) => data.redirectTo('/home'), // '/home': (_) => const HomeScreen(), // '/leaderboard': (_) => const LeaderboardScreen(), // '/settings': (_) => const SettingsScreen(), '/home': (_) { return RouteWidget( // transitionsBuilder: _fadeTransition, builder: (_) => const HomeScreen(), ); }, '/leaderboard': (_) { return RouteWidget( // transitionsBuilder: _fadeTransition, builder: (_) => const LeaderboardScreen(), ); }, '/settings': (_) { return RouteWidget( // transitionsBuilder: _fadeTransition, builder: (_) => const SettingsScreen(), ); }, }, ); void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp.router( title: 'Material App', routerDelegate: navigator.routerDelegate, routeInformationParser: navigator.routeInformationParser, ); } } class WrapperScreen extends StatelessWidget { const WrapperScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final location = context.routeData.location; return Scaffold( body: context.routerOutlet, bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, onTap: (index) { log(location); switch (index) { case 0: navigator.toReplacement('/home'); break; case 1: navigator.toReplacement('/leaderboard'); break; case 2: navigator.toReplacement('/settings'); break; default: } }, showSelectedLabels: false, showUnselectedLabels: false, items: const [ BottomNavigationBarItem( icon: Icon(Icons.home), label: '', ), BottomNavigationBarItem( icon: Icon(Icons.leaderboard), label: '', ), BottomNavigationBarItem( icon: Icon(Icons.settings), label: '', ), ], ), ); } } abstract class BaseScreen extends StatelessWidget { const BaseScreen({Key? key}) : super(key: key); String get title; @override Widget build(BuildContext context) { return Center( child: Text( title, style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 36, ), ), ); } } class HomeScreen extends BaseScreen { const HomeScreen({Key? key}) : super(key: key); @override String get title => "Home"; } class LeaderboardScreen extends BaseScreen { const LeaderboardScreen({Key? key}) : super(key: key); @override String get title => "Leaderboard"; } class SettingsScreen extends BaseScreen { const SettingsScreen({Key? key}) : super(key: key); @override String get title => "Settings"; } ```
GIfatahTH commented 2 years ago

@Reprevise Thanks for the issue. It is fixed.