unable to use both useFuture() and useValueChanged() in same HookWidget

933 views Asked by At

I have a hook widget with useValueChanged listener as follows:

    useValueChanged(selectedLayout.value, (_, __) {
      changeLayout(selectedLayout.value);
    });

and changeLayout(..) uses useFuture(..) to make a graphql mutation call and return a Future wrapped inside a AsyncSnapshot

the value is changed in onTap callback as follows:

    onTap: () {
      selectedLayout.value = "classic";
    },

my HookWidget is throwing type mismatch error. any way to use useFuture() and useValueChanged() in same HookWidget?

Bad state: Type mismatch between hooks:
- previous hook: _ValueChangedHook<String, Null>
- new hook: _FutureHook<QueryResult>
1

There are 1 answers

0
MOHIT CHOUDHARY On

I was stuck in useValueChanged but I got the way to do it. Here is the code :

useValueChanged(state, (_, __) {
  return controller.animateTo(
      min(controller.position.maxScrollExtent, controller.offset + 50.0),
      duration: Duration(seconds: 10),
      curve: Curves.linear);
});

This worked fine for me.