Flutter Beamer pass and retrieve data and getting NULL

208 views Asked by At

I am using the Beamer library in one of my projects, and I cannot pass a value to another location. For example, I wrote this code to navigate:

Beamer.of(context).beamToNamed('/homePage/chefStoreHomePage', 
   data: 
     {
       'chefStoreId': 9
     }
);

Here, I expect to pass an object named chefStoreId with a value of 9, and then receive it in the implementation code below:

class HomeScreenTab extends BeamLocation<BeamState> {
  HomeScreenTab(super.routeInformation);

  @override
  List<String> get pathPatterns => ['/homePage/*'];

  @override
  List<BeamPage> buildPages(BuildContext context, BeamState state) {
    final pages = [
      const BeamPage(
        key: ValueKey('/homePage'),
        title: 'Home',
        type: BeamPageType.noTransition,
        child: HomeRootScreenWidget(),
      ),
    ];
    int chefStoreId = int.tryParse(state.pathParameters['chefStoreId']!);
    pages.add(BeamPage(
      key: ValueKey('/homePage/chefStoreHomePage-$chefStoreId-${DateTime.now()}'),
      title: 'Chef Store',
      type: BeamPageType.slideRightTransition,
      child: ChefStoreWidget(),
    ));

    return pages;
  }
}

Here, I need to receive the number and assign it to chefStoreId:

int chefStoreId = int.tryParse(state.pathParameters['chefStoreId']!);

And in the ChefStoreWidget class, I want to receive this value using the context:

var note = context.currentBeamLocation.state.data['chefStoreId'];

However, I always receive null in all of my attempts to receive the value.

0

There are 0 answers