get_hooked 0.2.2 copy "get_hooked: ^0.2.2" to clipboard
get_hooked: ^0.2.2 copied to clipboard

Shared state with flutter_hooks! Inspired by riverpod and get_it.

example/lib/main.dart

import 'package:example/counter/counter.dart';
import 'package:example/form/form.dart';
import 'package:flutter/material.dart';
import 'package:get_hooked/get_hooked.dart';

void main() => runApp(const App());

enum Screen { counter, form }

final getScreen = Get.it(Screen.counter);

class App extends HookWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return switch (Ref.watch(getScreen)) {
      Screen.counter => const Counter(),
      Screen.form => const FormExampleApp(),
    };
  }
}

class ScreenSelect extends StatelessWidget {
  const ScreenSelect({super.key});

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        children: [
          for (final screen in Screen.values)
            ListTile(
              title: Text(screen.name),
              onTap: () {
                getScreen.value = screen;
                Scaffold.maybeOf(context)?.closeDrawer();
              },
            ),
        ],
      ),
    );
  }
}
0
likes
130
points
119
downloads

Publisher

verified publisherno-tolls.dev

Weekly Downloads

Shared state with flutter_hooks! Inspired by riverpod and get_it.

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #animation #state-management

License

MIT (license)

Dependencies

collection, collection_notifiers, flutter, meta

More

Packages that depend on get_hooked