features 1.0.0+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

pub package Buy Me A Coffee Donate

features #

A Flutter package to help with scoping features for a project.

Online Demo: https://rodydavis.github.io/features/

Getting Started #

Create a feature:

Feature _feature = Feature('counter');

Enable/Disable a feature:

Feature _feature.enabled = false;
Feature _feature.enabled = true;

Use a feature builder to react to changes:

floatingActionButton: FeatureBuilder(
    feature: _counterFeature,
    hideOnInactive: true,
    builder: (context, enabled, child) => FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
),
),

Use a feature provider:


Features(
    items: <Feature>[],
    child: Container(),
)

final _features = Features.of(context);

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:convert';

import 'package:features/features.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.blue),
      darkTheme: ThemeData.dark(),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  final _counterFeature = Feature('counter'); //..defaultValue(false)

  SharedPreferences _prefs;

  @override
  void initState() {
    SharedPreferences.getInstance().then((prefs) {
      _prefs = prefs;
      _restoreFromCache();
    });
    super.initState();
  }

  void _restoreFromCache() {
    final _savedCache = _prefs.getString('cache');
    final Map<String, dynamic> _cache = json.decode(_savedCache);
    _counterFeature.enabled = _cache[_counterFeature.key];
  }

  void _saveToCache() {
    final _cache = <String, dynamic>{};
    _cache[_counterFeature.key] = _counterFeature.enabled;
    _prefs.setString('cache', json.encode(_cache));
  }

  void _incrementCounter() {
    if (mounted)
      setState(() {
        _counter++;
      });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Container(
          width: 250,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
              FeatureBuilder(
                feature: _counterFeature,
                builder: (context, enabled, child) => SwitchListTile(
                  title: Text('Enable Counter'),
                  value: enabled,
                  onChanged: (val) {
                    _counterFeature.enabled = val;
                    _saveToCache();
                  },
                ),
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FeatureBuilder(
        feature: _counterFeature,
        hideOnInactive: true,
        builder: (context, enabled, child) => FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • features that is a package requiring null.

Health suggestions

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

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

line 5 col 16: The field doesn't override an inherited getter or setter.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
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