flutter-provider

Flutter Riverpod - using read() inside build method

余生长醉 提交于 2021-01-29 07:18:04
问题 Suppose I want to initialize a text field by using the initialValue: property on a TextFormField , and I need my initial value to come from a provider. I read on the docs that calling read() from inside the build method is considered bad practice, but calling from handlers is fine (like onPressed ). So I'm wondering if its fine to call read from the initialValue property like shown below? 回答1: No, you should use useProvider if you are using hooks, or a ConsumerWidget / Consumer if you are not

StreamProvider not updating List

浪尽此生 提交于 2021-01-28 05:10:16
问题 I have a StreamController which should update a List but it doesn't happen: class LocationService { StreamController<List<bg.Geofence>> geofencesController = StreamController<List<bg.Geofence>>(); updateGeofences(geofences) { logger.i('listing geofences $geofences'); geofencesController.add(List.from(list)); } } When I call updateGeofences I got many geofences in logs. But widget are not rebuilt! Here is my providers setup: class MyApp extends StatelessWidget { @override Widget build

Provider vs. Get_it

送分小仙女□ 提交于 2021-01-20 19:00:31
问题 Searching for Dependency Injection solutions for Flutter, I found two awesome libraries: provider and get_it . As far as I can see, provider has more boilerplate, but it fits really nicely with Flutter, allowing Consumer to rebuild parts of the Widget tree onde an injected value change. get_it on the other hand is more straightforward, easier to use, and not dependant on Flutter, so can be used with any Dart code. Are there any more differences and limitations between them? I know this is

How to use textEditiing controller with Provider in Flutter

心不动则不痛 提交于 2020-12-06 04:14:05
问题 I am using provider for state management. I am in a situation where there are multiple types of fields in my form. The problem is with text-field Whenever I change Text it is behaving weirdly like the text entered is displayed in reverse order. class MyProvider with ChangeNotifier{ String _name; String get name => _name; setname(String name) { _name = name; notifyListeners(); } } class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { final MyProvider