flutter_hooks_extra 0.0.1 flutter_hooks_extra: ^0.0.1 copied to clipboard
Some Flutter hooks base on flutter_hooks.
flutter_hooks_extra #
Some Flutter hooks base on flutter_hooks.
useFutureState #
Hook to manage asynchronous data
For the hooks for managing asynchronous data, the API is very close to the useRequest of ahooks, which achieves 70% of the functions, and will try to be fully transplanted in the future.
Example:
import 'package:flutter_hooks_extra/flutter_hooks_extra.dart';
Future<String> createOrderMessage(params) async {
var order = await fetchUserOrder();
return 'Your order is: $order';
}
Future<String> fetchUserOrder() =>
// Imagine that this function is
// more complex and slow.
Future.delayed(
Duration(seconds: 2),
() => 'Large Latte',
);
class HomePage extends HookWidget {
@override
Widget build(BuildContext context) {
final delayDataReq = useFutureState(createOrderMessage,
options: FutureHookOptions(
manual: true,
onSuccess: (data, params) {
print(data);
print(params);
}));
useEffect(() {
delayDataReq.run!();
return;
}, []);
More hooks will be added in the future...