-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove globalAppStore
and add provider pattern for it
#733
Conversation
globalAppStore
and add provider pattern for it.
globalAppStore
and add provider pattern for it.globalAppStore
and add provider pattern for it
# Conflicts: # lib/app.dart # lib/main.dart # lib/page-encointer/bazaar/0_main/bazaar_main.dart # lib/page-encointer/home_page.dart # lib/page/account/create/add_account_page.dart # lib/page/account/create/create_account_page.dart # lib/page/account/create/create_pin_page.dart # lib/page/account/create_account_entry_page.dart # lib/page/account/import/import_account_page.dart # lib/page/assets/receive/receive_page.dart # lib/page/assets/transfer/detail_page.dart # lib/page/assets/transfer/payment_confirmation_page/index.dart # lib/page/assets/transfer/transfer_page.dart # lib/page/network_select_page.dart # lib/page/profile/account/account_manage_page.dart # lib/page/profile/account/change_password_page.dart # lib/page/profile/account/export_account_page.dart # lib/page/profile/contacts/account_share_page.dart # lib/page/profile/contacts/contact_detail_page.dart # lib/page/profile/contacts/contact_list_page.dart # lib/page/profile/contacts/contact_page.dart # lib/page/profile/contacts/contacts_page.dart # lib/page/profile/settings/remote_node_list_page.dart # lib/page/profile/settings/settings_page.dart # lib/page/profile/settings/ss58_prefix_list_page.dart # lib/page/qr_scan/qr_scan_page.dart # lib/page/reap_voucher/reap_voucher_page.dart # test_driver/app.dart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have to request some systematic change for this PR. It seems in most of the places, we should use context.watch
(sometimes context.select
), instead of context.read
.
- See, don't use
context.read
in build methods: Why is it unsafe to usecontext.read
insidebuild
? rrousselGit/provider#456 - Example 1 explaining provider: https://meysam-mahfouzi.medium.com/understanding-state-management-using-providers-in-flutter-7154c6968a3f
- Example 2 explaining provider with mobx: https://itnext.io/flutter-state-management-with-mobx-and-providers-change-app-theme-dynamically-ba3b60619050
With context.watch
, we can still assign a variable inside the widget:
final store = context.watch<AppStore>
and we will still be notified about state changes from the appStore, which will trigger a rebuild. Please come forward if I have misunderstood something.
It was not good to use context.read() in build method, I corrected it to context.watch() and context.select() in needed places. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just noticed that I accidentally approved instead of requesting changes. I will review later again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I tested a basic encointer meetup with the test network, and it was successful, so I think the new provider pattern works as intended, good job! :)
I only have some minor comments, and questions.
One general point: I would like you to clean up the code a bit by assigning a variable final store = context.read<AppStore>
, where we have many context.read
s now. I think it makes the code more readable at many places. Do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your patience and fixes. Only one question remains. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for the hard work on for your patience!
// On test mode instead of LocalStorage() must be use MockLocalStorage() | ||
create: (context) => AppStore(util.LocalStorage()), | ||
child: const WalletApp(Config()), | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, I see I did not get that before, this is one of the beauties of using the provider; we don't even need to check the config. :D
Thanks for the comment. It is helpful!
Deleted global app store. Created Provider pattern for global store. Subtask of #132.