Uses useFuture with an additional retry method to easily retry/refresh the future function.
dependencies:
flutter_use: class Sample extends HookWidget {
@override
Widget build(BuildContext context) {
final state = useFutureRetry(Future.delayed(const Duration(seconds: 2), () {
return 'Fetched :${DateTime.now()}';
}));
return Column(
children: [
state.snapshot.connectionState == ConnectionState.done
? Text('Value: ${state.snapshot.data}')
: const Text('Loading...'),
ElevatedButton(
onPressed: () => state.retry(),
child: const Text('Retry'),
),
]
);
}
}