Skip to content

Commit

Permalink
Merge pull request #3790 from nestorsgarzonc/patch-1
Browse files Browse the repository at this point in the history
Update random number example from StateNotifier to NotifierProvider
  • Loading branch information
rrousselGit authored Oct 21, 2024
2 parents 0da12bc + cead49e commit 305b92d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/random_number/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ void main() {
runApp(const ProviderScope(child: RandomNumberApp()));
}

// State notifier for generating a random number exposed by a state notifier
// Notifier for generating a random number exposed by a state notifier
// provider
class RandomNumberGenerator extends StateNotifier<int> {
RandomNumberGenerator() : super(Random().nextInt(9999));
class RandomNumberGenerator extends Notifier<int> {
@override
int build() => Random().nextInt(9999);

void generate() {
state = Random().nextInt(9999);
}
}

// State notifier provider holding the state
final randomNumberProvider = StateNotifierProvider(
(ref) => RandomNumberGenerator(),
);
// Notifier provider holding the state
final randomNumberProvider =
NotifierProvider<RandomNumberGenerator, int>(RandomNumberGenerator.new);

class RandomNumberApp extends StatelessWidget {
const RandomNumberApp({super.key});
Expand Down

0 comments on commit 305b92d

Please sign in to comment.