flhooks 0.0.1

  • README.md
  • Installing
  • Versions
  • 60

flhooks #

React like Hooks implementation for Flutter.

This package is inspired by React Hooks.

This is a work in progress, fell free to fork or open issues.

Getting Started #

You should ensure that you add the flhooks as a dependency in your flutter project.

 flhooks: "^0.0.1"

You should then run flutter packages upgrade or update your packages in IntelliJ.

Rules #

When using Hooks, React Hooks rules must be followed.

Only Call Hooks at the Top Level #

Don’t call Hooks inside loops, conditions, or nested functions. Hooks can only be used inside a HookBuilder builder params. They can also be used to create other hooks.

Example #

Simple Usage #

Hooks can only be used inside the builder of an HookBuilder.

// Define a Slider Page
final SliderPage = () =>
      builder: (BuildContext context) {
        // define a state of type double
        final example = useState(0.0); 
        final onChanged = useCallback((double newValue) {
          // call example.set for update the value in state
        }, [example]);
        return Material(
          child: Center(
            child: Slider(
              key: sliderKey,
              value: example.value,
              onChanged: onChanged,
// Start the app
void main() =>
      home: SliderPage(),

Custom Hooks #

Custom Hooks name must start with 'use'.

class MultipliedState {
  const DoublerState(this.value, this.set);

  final value;
  final set;

final useMultiplied = (initial, multiplier) {
  final state = useState(inital);
  final set = useCallback((value) => state.set(value * multiplier),
      [state, multiplier]);
  return MultipliedState(
    value: state.value,
    set: set,

Now you can use useMultiplied like any other hooks.

Hooks #

Currently implemented Hooks.

useMemo #

useMemo take a function, fn, and the values, store, used in the function as input, return the value of the call fn(), recall fn() only if store changed.

final helloMessage = useMemo(() => 'Hello ${name}', [name]);
// the fn passed to useMemo will be recalled only if name change

useCallback #

useCallback take a function, fn, and the values, store, used in the function as input, return the same reference to fn until the store change.

final onClick = useCallback(() => ..., [input1, input2]);
// return always the same reference to the first fn passed to useCallback
// until input1 or input2 change
// it's like passing an high order function to useMemo

useState #

useState take the initial value as input and return an HookState with the current value and the set function.

final name = useState('');
// ... get the value
//... update the value
onChange: (newValue) => name.set(newValue);

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flhooks: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flhooks/flhooks.dart';
Version Uploaded Documentation Archive
1.1.0 Jan 5, 2019 Go to the documentation of flhooks 1.1.0 Download flhooks 1.1.0 archive
1.0.1 Dec 25, 2018 Go to the documentation of flhooks 1.0.1 Download flhooks 1.0.1 archive
1.0.0 Dec 25, 2018 Go to the documentation of flhooks 1.0.0 Download flhooks 1.0.0 archive
0.0.2 Dec 24, 2018 Go to the documentation of flhooks 0.0.2 Download flhooks 0.0.2 archive
0.0.1 Dec 23, 2018 Go to the documentation of flhooks 0.0.1 Download flhooks 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16
  • Flutter: 1.5.4-hotfix.2


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flhooks.dart.

Run flutter format to format lib/flhooks.dart.

Maintenance suggestions

The package description is too short. (-16 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flhooks.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies