flutter_hooks 0.13.0

Flutter Android iOS web

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 'star_wars/planet_screen.dart';
import 'use_effect.dart';
import 'use_state.dart';
import '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(),
          ),
          _GalleryItem(
            title: 'Star Wars Planets',
            builder: (context) => PlanetScreen(),
          )
        ]),
      ),
    );
  }
}

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

  final String title;
  final WidgetBuilder builder;

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

Publisher

dash-overflow.net

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_hooks