Skip to content

Can't rebuild MaterialApp using riverpod generator #3482

Answered by gdurandrexel
binaerverkehr asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to mutate the state of a provider, you must put the mutating methods inside the provider and update the provider's state inside them.
You can call these methods via the provider's notifier (which you must read).

If you are using VS Code and Riverpod snippets, this is the one called riverpodClass. This will generate a provider called appThemeProvider (name of the class+Provider).

@riverpod
class AppTheme extends _$AppTheme {
  @override
  bool build() { // bool is the type of the value this provider provides (can be any type)
    return false; // this is your initial state
  }

  void toggleTheme() {
    state = !state; // here you set the state of the provider with whatever va…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@binaerverkehr
Comment options

@binaerverkehr
Comment options

Answer selected by binaerverkehr
Comment options

You must be logged in to vote
2 replies
@binaerverkehr
Comment options

@binaerverkehr
Comment options

Comment options

You must be logged in to vote
4 replies
@binaerverkehr
Comment options

@binaerverkehr
Comment options

@gdurandrexel
Comment options

@binaerverkehr
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants