stacked_hooks 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

Stacked Hooks #

This package contains widgets that allow you to use the Flutter Hooks package with the ViewModelWidget in the stacked architecture.

HookViewModelWidget #

The ViewModelWidget is an implementation of a widget class that returns a value provided by Provider as a parameter in the build function of the widget. This allows for easier consumption and use of viewmodels without boilerplate. The HookViewModelWidget allows you to use this widget and make use of Flutter Hooks inside the build function. This is very useful when you want to use TextEditting controllers and you're implementing this architecture.

// View that creates and provides the viewmodel
class HookViewModelWidgetExample extends StatelessWidget {
  const HookViewModelWidgetExample({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ViewModelBuilder<HomeViewModel>.nonReactive(
      builder: (context, model, child) => Scaffold(
          body: Center(
        child: _HookForm(),
      )),
      viewModelBuilder: () => HomeViewModel(),
    );
  }
}

// Form that makes use of the ViewModel provided above but also makes use of hooks
class _HookForm extends HookViewModelWidget<HomeViewModel> {
  @override
  Widget buildViewModelWidget(BuildContext context, HomeViewModel model) {
    var title = useTextEditingController();
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Text(model.title),
        TextField(
          controller: title,
          onChanged: model.updateTile,
        )
      ],
    );
  }
}

// ViewModel
class HomeViewModel extends BaseViewModel {
  String title = 'default';

  void updateTile(String value) {
    title = value;
    notifyListeners();
  }
}

0.1.2 #

  • Hook widget has a const constructor

0.1.1+3 #

  • Changelog style updates

0.1.1+2 #

  • Added key to HookViewModelWidget constructor

0.1.1+1 #

  • Updates webpage for package

0.1.1 #

  • Export Hooks file

0.1.0 #

  • Adds HookViewModelWidget

example/lib/main.dart

import 'package:flutter/material.dart';

import 'ui/views/hook_viewmodel_widget/hook_viewmodel_widget_example.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: HookViewModelWidgetExample(),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  stacked_hooks: ^0.1.2

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:stacked_hooks/stacked_hooks.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
91
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jul 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • stacked_hooks that is a package requiring null.

Health suggestions

Format lib/stacked_hooks.dart.

Run flutter format to format lib/stacked_hooks.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

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

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_hooks ^0.9.0 0.9.0 0.12.0
provider ^4.0.5 4.3.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
nested 0.0.4
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test