frhooks 1.3.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 59

Frhooks #

Build Status

use react like hooks in flutter.

Motivation #

Have the same thinking of the flutter_hooks motivation. React hooks is more brief to manage local state, and StatefulWidget are verbose. This library brings hooks to flutter. If your are React person, you will like it.

Usage #

useContext #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    BuildContext context = useContext() 
    return Container()
  }
}

useState #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    StateContainer result = useState(0)
    // result.state
    // result.setState
    return Container()
  }
}

useEffect #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    useEffect(() {
      // do effect here.
      return () {
        // remove effect here
      }
    })
    return Container()
  }
}

useCallback #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    var callback = useCallback(() {
      return 1
    }, [])
    // result == 1
    var result = callback()
    return Container()
  }
}

useMemo #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    var c = useMemo(() => computeExpensiveValue(a, b), [a, b]);
    return Container()
  }
}

useRef #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    final ref = useRef();
    // free to set and read ref.current
    return Container()
  }
}

useAnimationController #

class MyWidget extends HookWidget {
  Widget build(BuildContext context) {
    final controller = useAnimationController();
    // controller.forward()
    return Container()
  }
}

1.0.0 #

  • Initial version, created by Stagehand

1.2.0 #

fix: update can rebuild widget correctly.

  • refactor:HookElement now extends from ~~ComponentElement~~StatelessElement
  • refactor: HookWidget now extends from ~Widget~StatelessWidget

1.2.2 #

feature: useMemo receive a thunk to lazy compute.

1.2.3 #

feature: hotload will reset hook in Element.

1.2.4 #

fix: reassemble will clear effect.

1.2.5 #

feature: if you insert or remove a hook in your build method, frhooks will rerun the build method and drop the memorized state.

1.2.6 #

fix: frhooks can rerun your hooks correctly after insert or remove one hook.

1.2.7 #

fix: use addPostFrameCallback instead of manual calling didBuild in build.

1.2.8 #

fix: move addPostFrameCallback into willBuild & clean unnecessary variables(currentHookLength & prevHookLength).

1.2.9 #

fix: move _workInProgressHook = null; into willBuild.

1.3.0 #

feature: new hooks useRef. feature: new hooks useAnimationController.

Use this package as a library

1. Depend on it

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


dependencies:
  frhooks: ^1.3.0

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:frhooks/frhooks.dart';
  
Version Uploaded Documentation Archive
1.3.0 Jun 22, 2019 Go to the documentation of frhooks 1.3.0 Download frhooks 1.3.0 archive
1.2.9 Jun 5, 2019 Go to the documentation of frhooks 1.2.9 Download frhooks 1.2.9 archive
1.2.8 Jun 2, 2019 Go to the documentation of frhooks 1.2.8 Download frhooks 1.2.8 archive
1.2.7 Jun 2, 2019 Go to the documentation of frhooks 1.2.7 Download frhooks 1.2.7 archive
1.2.6 May 30, 2019 Go to the documentation of frhooks 1.2.6 Download frhooks 1.2.6 archive
1.2.5 May 21, 2019 Go to the documentation of frhooks 1.2.5 Download frhooks 1.2.5 archive
1.2.4 May 19, 2019 Go to the documentation of frhooks 1.2.4 Download frhooks 1.2.4 archive
1.2.3 May 19, 2019 Go to the documentation of frhooks 1.2.3 Download frhooks 1.2.3 archive
1.2.2 May 16, 2019 Go to the documentation of frhooks 1.2.2 Download frhooks 1.2.2 archive
1.2.1 May 12, 2019 Go to the documentation of frhooks 1.2.1 Download frhooks 1.2.1 archive

All 14 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
56
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

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

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Fix lib/src/useAnimationController.dart. (-43.75 points)

Analysis of lib/src/useAnimationController.dart failed with 2 errors:

line 12 col 21: Undefined name 'kDebugMode'.

line 33 col 11: The named parameter 'reverseDuration' isn't defined.

Fix lib/src/hook.dart. (-0.50 points)

Analysis of lib/src/hook.dart reported 1 hint:

line 2 col 8: Don't import implementation files from another package.

Fix lib/src/hook_element.dart. (-0.50 points)

Analysis of lib/src/hook_element.dart reported 1 hint:

line 21 col 102: Avoid using braces in interpolation when not needed.

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

Fix analysis_options.yaml.

The analyzer can't parse analysis_options.yaml.

The package description is too short. (-20 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 frhooks.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.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
flutter_test