flutter_corelibrary
flutter_corelibrary copied to clipboard
Nested hook widgets trigger a `avoid_conditional_hooks` false positive
The following useState
is marked:
class W extends HookWidget {
const W({super.key});
@override
Widget build(BuildContext context) {
if (Random().nextBool()) {
return HookBuilder(
builder: (context) {
useState(1);
return const SizedBox();
},
);
}
return const SizedBox();
}
}
It shouldn't as it exists in a different hook scope. It happens because when analysing W
it looks for all used hooks inside of it. Instead it should stop recursing down once it encounters a new hook scope. This is done in helpers.dart@getAllInnerHookExpressions
.