Replies: 2 comments 6 replies
-
You cannot store state as properties of your widgets like this. |
Beta Was this translation helpful? Give feedback.
2 replies
-
@anfernydc what was the fix for you? I think I'm running into a similar issue. Here's my snippet. I have a widget to edit final fetchedWorkout = ref.watch(workoutProvider); // returns AsyncValue<WorkoutDefinition>
final definition = useState(null as WorkoutDefinition?);
useEffect(() {
fetchedWorkout.when(
data: (data) => definition.value = data, // <-- this is being hit correctly but the widget is not rebuilt
error: (error, stackTrace) { /* show error */ },
loading: () => definition.value = null,
);
return null;
}, [fetchedWorkout]); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a text controller where with each key entry, I'm updating an image, hence a rebuild. I've tried a number of ways to refocus back on the text box after the rebuild from useEffect(), and while visually the focus of the text box shows, I can't actually type anything unless I click on the text box (backspace works for some reason). I'm not sure why, my understanding of the rebuild process is lacking but can't seem to get an explanation.
Tried various different adjustments in useEffect(), also would like to avoid using autofocus parameter in the text box widget (whose code I also tried to use as a reference). All the solutions I've tried, however, work fine if I stop using flutter hooks and use setState().
In the example code provided, because it's a lot more basic, I have also worked around this in this example by not using useState('') and using useListener() and wrapping the text box widget with a focus widget (doesn't work with useState), but would like to solve this using useState() as I need it for my implementation.
Beta Was this translation helpful? Give feedback.
All reactions