utopia_hooks 0.3.2+1 copy "utopia_hooks: ^0.3.2+1" to clipboard
utopia_hooks: ^0.3.2+1 copied to clipboard

outdated

Utopia USS libs - basic and complex hooks (including SubmitState, ComputedState and supporting widgets)

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:utopia_hooks/utopia_hooks.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends HookWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final fieldState = useState("");

    final computedState = useAutoComputedState<String>(
      debounceDuration: const Duration(seconds: 1),
      compute: () async {
        if (kDebugMode) {
          print("Computing at ${DateTime.now().toIso8601String()}");
        }
        await Future.delayed(const Duration(seconds: 5));
        return fieldState.value + DateTime.now().toIso8601String();
      },
      keys: [fieldState.value],
    );

    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: Column(
          children: [
            StatelessTextEditingControllerWrapper(
              value: fieldState.value,
              onChanged: (value) => fieldState.value = value,
              child: (controller) => TextField(controller: controller),
            ),
            const SizedBox(height: 16),
            Expanded(
              child: Center(
                child: RefreshableComputedStateWrapper<String>(
                  state: computedState,
                  inProgressBuilder: (context) => const Text("InProgress"),
                  failedBuilder: (context) => const Text("Failed"),
                  builder: (context, value) => Text(value),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
8
likes
0
pub points
53%
popularity

Publisher

verified publisherutopiasoft.io

Utopia USS libs - basic and complex hooks (including SubmitState, ComputedState and supporting widgets)

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async, equatable, fast_immutable_collections, flutter, flutter_hooks, provider, utopia_utils

More

Packages that depend on utopia_hooks