rrousselGit / state_notifier

ValueNotifier, but outside Flutter and with some extra perks
MIT License
311 stars 28 forks source link

Extend `StateNotifier` from a generic class #67

Closed om-ha closed 2 years ago

om-ha commented 2 years ago

Describe the bug Cannot extend StateNotifier from a generic class

To Reproduce

Expected behavior To be able to use generic type with a class, and still extend StateNotifier.

Problem I am trying to solve

om-ha commented 2 years ago

Note: bug label might not be appropriate here, apologies.

om-ha commented 2 years ago

Looks like I got this to work:

final temperatureProvider = StateNotifierProvider<DataHolderStateNotifier, double?>((Ref ref) { return DataHolderStateNotifier( stringField: 'temperature', boolField: true, ); });

- Provider Usage
```dart
// read
int? counterValue = ref.watch(counterProvider);
double? temperatureValue = ref.watch(temperatureProvider);

// write
ref.watch(counterProvider.notifier).set(newValue: 100);
ref.watch(temperatureProvider.notifier).set(newValue: 24.42);

I hope this proves useful to others.