Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 873 Bytes

File metadata and controls

37 lines (30 loc) · 873 Bytes

useFutureRetry

Uses useFuture with an additional retry method to easily retry/refresh the future function.

Installation

dependencies:
  flutter_use: 

Usage

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'),
        ),
      ]
    );
  }
}