rrousselGit / flutter_hooks

React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
MIT License
3.13k stars 179 forks source link

TabBarView controller index with useState change #331

Closed ThomasAunvik closed 1 year ago

ThomasAunvik commented 1 year ago

Describe the bug When changing a State and changing the tab index trough the controller at the same time. It would seem to ignore the state.

To Reproduce

https://github.com/ThomasAunvik/flutter_state_bug_tabbar

https://github.com/ThomasAunvik/flutter_state_bug_tabbar/blob/41f409c1c1790a50385bdbd98ab99d41b9984155/lib/main.dart#L54-L66

Remove the commented out //tabController.index = 1; to make the bug happen.

Minimal Example:

final submittedValue = useState<String?>(null);

TabBarView(
  controller: tabController,
  children: [
    FirstWidget(
      submit: (value) {
        submittedValue.value = value;
        tabController.index = 1;
      },
    ),
    PreviewWidget(
      submittedValue.value,
    ),
  ],
)

https://user-images.githubusercontent.com/9968151/201919080-c1845f05-b538-4804-8c7b-95545906f746.mp4

Expected behavior State should also reflect on the second page.

ThomasAunvik commented 1 year ago

Attempted this with normal flutter state, seems to be a not-issue for flutter_hooks.

Found similar issues after a bit more searches when it was generally flutter problem.

Thanks to this answer: https://stackoverflow.com/a/73649920/7589365