Obisi7
Obisi7

Reputation: 525

Flutter switch button not activated using Riverpod

I am employing Riverpod for state management via StateNotifierProvider. My switch button just won't enable upon clicking and thus no state changes to effect theme mode switching. I have spent a ton of hours researching similar issues but none like mine as I am not using setState(). I expect the state of the button to change on clicking on dragging but the thumb of the switch just returns to its initial off position. Please help me with what I am doing wrong. Here are snapshots of my main.dart, home_screen.dart, and the theme controller notifier as I am unable to copy and paste my code correctly as advised with 4 spaces.

theme_controler

home Screen with switch button defined in appbar main.dart app UI showing switch remains in default state

Upvotes: 0

Views: 1878

Answers (1)

You need to update the state (not the _isDarkvariable) this way:

toggleTheme(bool value) {
  state = value;
  _safePrefs;
}

The image is not complete, so I can't see the use of _isDark variable (Probably nothing). But You shoul be fine now, at least updating the state.

Upvotes: 2

Related Questions