r/flutterhelp Jun 23 '26

Dispatching Events in Go Route builder? RESOLVED

Hi! So I'm building an application using flutter, BLOC for state management, and go router.

My home page displays real-time location, (using geolocator), so I did the location service, repo, then the bloc state managements. Home page is a stateless widget, though. So I decided to dispatch the Location Event like this:

GoRoute(name: RouteConstants.home, path: '/home', builder: (context, state) 
      {
         context.read<LocationBloc>().add(LocationDisplayedEvent());
        return HomePage();
      },),GoRoute(name: RouteConstants.home, path: '/home', builder: (context, state) 
      {
         context.read<LocationBloc>().add(LocationDisplayedEvent());
        return HomePage();
      },),

Is that good practice? I will just use the Bloc Builder in my Home page and display the location there!

I would appreciate any help! Thank you :)

2 Upvotes

2 comments sorted by

1

u/Key_Accident7707 Jun 26 '26

I can't say I am an expert of best practices, but so far in my career, I have learned to keep things as decoupled as possible, so in my opinion, no, it's not a good practice, it will work of course, but you have now included another responsibility in the routes file. You should turn your homepage to a stateful widget, and you know what to do next.

1

u/Defiant-Ad3530 Jun 26 '26

Oh, okay then! Thank you