Closed2
flutter_hooks周りのマイグレーションでのエラーの解消

アプリのライブラリなどを最新化するにあたってビルド時にエラーが発生した。
======== Exception caught by widgets library =======================================================
The following assertion was thrown building RankingScreen(dirty, dependencies: [UncontrolledProviderScope], state: _ConsumerState#a8efc):
Hooks can only be called from the build method of a widget that mix-in `Hooks`.
Hooks should only be called within the build method of a widget.
Calling them outside of build method leads to an unstable state and is therefore prohibited.
'package:flutter_hooks/src/framework.dart':
Failed assertion: line 133 pos 12: 'HookElement._currentHookElement != null'
flutter_fooksをこの画面だけに使っているので原因だと思われる
他の画面の実装との違いは extendsしているのが ConsumerWidgetsだったのでHooksConsumerWidgetsに変更したら解決した。

flutterやDartのライブラリ上げたのでそこでビルド時エラーになったのかも。riverpod_hookをあげたせいじゃないような。diffを掲載しておく。
- flutter_hooks: ^0.18.0
- hooks_riverpod: ^2.1.3
+ flutter_hooks: ^0.20.5
+ hooks_riverpod: ^2.6.1
このスクラップは2024/12/30にクローズされました