flutter_hooks_extra 0.0.1 copy "flutter_hooks_extra: ^0.0.1" to clipboard
flutter_hooks_extra: ^0.0.1 copied to clipboard

outdated

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...

5
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Some Flutter hooks base on flutter_hooks.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_hooks

More

Packages that depend on flutter_hooks_extra