Skip to main content
Version: 8.5.0

Hooks

If you like flutter_hooks the GOOD NEWS is that flutter meedu is compatible with hooks.

First add hooks_meedu to your pubspec.yaml

dependencies:
hooks_meedu: ^0.0.1

Now you can use the HookConsumerWidget class to create a widget that can works with hooks and meedu at the same time.

class HookConsumerTest extends HookConsumerWidget {
const HookConsumerTest({super.key});
@override
Widget build(BuildContext context, BuilderRef ref) {
final count = useState(0);
final state = ref.watch(myProvider).state;
return YOUR_WIDGET;
}
}

Also you can use the HookConsumer widget.

HookConsumer(
builder: (_, ref, child) {
final text = useState("");
final state = ref.watch(myProvider).state;
return YOUR_WIDGE;
},
)

If you need to work with a StatefulWidget, hooks and flutter meedu you can use the StatefulHookConsumerWidget class.

class HookStatefulTest extends StatefulHookConsumerWidget {
const HookStatefulTest({super.key});
@override
HookStatefulTestState createState() => HookStatefulTestState();
}
class HookStatefulTestState extends ConsumerState<HookStatefulTest> {
int count = 0;
@override
Widget build(BuildContext context) {
final count2 = useState(0);
final state = ref.watch(provider).state;
return GestureDetector(
onTap: () {
count2.value++;
setState(() => count++);
},
child: OTHER_WIDGET,
);
}
}
Last updated on by darwin-morocho