zubairehman / flutter_boilerplate_project

A boilerplate project created in flutter using MobX and Provider.
http://zubairehman.surge.sh/
MIT License
2.26k stars 905 forks source link

Replace provider by get_it #113

Closed quanghd96 closed 2 years ago

quanghd96 commented 2 years ago

I see get_it can be used instead of Provider. So why you use both it?

// in service_locator.dart getIt.registerSingleton(ThemeStore(getIt()));

// myapp.dart Provider(create: () => _themeStore),

I think we only need to use ThemeStore by get_it or provider. Not need both

dyardy commented 2 years ago

This is similar to https://github.com/zubairehman/flutter-boilerplate-project/issues/118

I understand using Provider to get from singleton (getIt) in one location and making it available in different locations in the tree/hierarchy however I do not see the reason for new-ing it up as found in my_app.dart final PostStore _postStore = PostStore(getIt<Repository>());

when you may just get from getIt via final PostStore _postStore = getIt<PostStore>();

There are some confusing patterns within this repo. In addition to the above, I see FormStore reference within login.dart. This class unlike other stores is newed up within login.dart however the other stores are registered with getIt. Why a different approach with FormStore() final _store = FormStore();

I am confused by the inconsistencies with registering some class with DI (getIt), registrations with Provider and also newing up classes. I am hoping you can provide some 'approach' that will help clarify the inconsistencies.

zubairehman commented 2 years ago

Hi @dyardy,

Thanks for pointing it out. Please follow this branch for upcoming changes: https://github.com/zubairehman/flutter-boilerplate-project/tree/feature/mvi

I will make sure to merge the DI-related changes in the master branch as well. Let me know if you have any comments.

Thanks