flutter_hooks 0.5.0 copy "flutter_hooks: ^0.5.0" to clipboard
flutter_hooks: ^0.5.0 copied to clipboard

outdated

A flutter implementation of React hooks. It adds a new kind of widget with enhanced code reuse.

example/lib/main.dart

// ignore_for_file: omit_local_variable_types
import 'package:flutter/material.dart';
import 'package:flutter_hooks_gallery/use_effect.dart';
import 'package:flutter_hooks_gallery/use_state.dart';
import 'package:flutter_hooks_gallery/use_stream.dart';

void main() => runApp(HooksGalleryApp());

/// An App that demonstrates how to use hooks. It includes examples that cover
/// the hooks provided by this library as well as examples that demonstrate
/// how to write custom hooks.
class HooksGalleryApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Hooks Gallery',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Hooks Gallery'),
        ),
        body: ListView(children: [
          _GalleryItem(
            title: 'useState',
            builder: (context) => UseStateExample(),
          ),
          _GalleryItem(
            title: 'useMemoize + useStream',
            builder: (context) => UseStreamExample(),
          ),
          _GalleryItem(
            title: 'Custom Hook Function',
            builder: (context) => CustomHookExample(),
          ),
        ]),
      ),
    );
  }
}

class _GalleryItem extends StatelessWidget {
  final String title;
  final WidgetBuilder builder;

  const _GalleryItem({this.title, this.builder});

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(title),
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute<void>(
            builder: builder,
          ),
        );
      },
    );
  }
}
2211
likes
0
pub points
99%
popularity

Publisher

verified publisherdash-overflow.net

A flutter implementation of React hooks. It adds a new kind of widget with enhanced code reuse.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_hooks