pref_gen 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

pref_gen #

Generator to create boilerplate for shared preferences based on a provided interface.
The generated code is platform agnostic, there's an adapter interface inside the pref_gen_annotations package that can be used to inject an implementation based on the platform project.
This choice was made to give developers the ability to model persistance rapidly into packages shared between Flutter and Web apps.

Usage #

Suppose the shared model package is called A and B the platform specific annotation.

  1. Add this package as a dev dependency to your A/pubspec.yaml.
  2. Add pref_gen_annotations as a dependency to your A/pubspec.yaml
  3. Annotate classes with the PreferencesHolder (or the ReactivePreferencesHolder) annotation.
  4. Run pub run build_runner build to start the code generation.
  5. Comsume the generated code into the A package.
  6. Add pref_gen_flutter in B/pubspec.yaml and inject from B the implementation of the adapter for Flutter into the model.
  7. Consume the model into the views.

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:pref_gen_flutter/pref_gen_flutter.dart';
import 'package:pref_gen_annotations/pref_gen_annotations.dart';
import 'package:rxdart/rxdart.dart';
import 'dart:async';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
part 'main.g.dart';

Color pickerColor = Color(0xff443a49);
Color currentColor = Color(0xff443a49);

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Preferences Generator Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

@ReactivePreferencesHolder()
abstract class SharedSettings implements SharedSettingsPreferences {
  int counter;
  int appbarColor;

  factory SharedSettings(PreferenceAdapter adapter) = _$SharedSettings;
}

class MyHomePage extends StatelessWidget {
  final SharedSettings settings = SharedSettings(SharedPreferencesAdapter());

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<int>(
      stream: settings.appbarColorStream,
      builder: (BuildContext context, AsyncSnapshot appbarColorSnapshot) {
        return Container(
          child: Scaffold(
            appBar: AppBar(
              backgroundColor: Color(appbarColorSnapshot.data ?? 0),
              title: Text("Generated settings demo"),
              actions: <Widget>[
                _buildPickerDialogAction(context),
              ],
            ),
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'You have pushed the button this many times:',
                  ),
                  StreamBuilder<int>(
                    stream: settings.counterStream,
                    builder: (BuildContext context, AsyncSnapshot snapshot) {
                      return Container(
                        child: Text(
                          '${snapshot.data ?? 0}',
                          style: Theme.of(context).textTheme.display1,
                        ),
                      );
                    },
                  ),
                ],
              ),
            ),
            floatingActionButton: FloatingActionButton(
              onPressed: () => settings.counter = (settings.counter ?? 0) + 1,
              tooltip: 'Increment',
              child: Icon(Icons.add),
            ),
          ),
        );
      },
    );
  }

  Widget _buildPickerDialogAction(BuildContext context) => IconButton(
      icon: new Icon(Icons.colorize),
      tooltip: 'Change appbar color',
      onPressed: () {
        showDialog(
          context: context,
          builder: (context) => AlertDialog(
                  title: const Text('Pick a color!'),
                  content: SingleChildScrollView(
                    child: ColorPicker(
                      pickerColor: pickerColor,
                      onColorChanged: (color) =>
                          settings.appbarColor = color.value,
                      enableLabel: true,
                      pickerAreaHeightPercent: 0.8,
                    ),
                  ),
                  actions: <Widget>[
                    FlatButton(
                      child: Text('Got it'),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ]),
        );
      });
}

Use this package as a library

1. Depend on it

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


dependencies:
  pref_gen: ^0.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:pref_gen/pref_gen.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
89
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
38
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:pref_gen/pref_gen.dartpackage:pref_gen/generator/generator.dartpackage:pref_gen/generator/reactive_preferences.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Health suggestions

Fix lib/generator/common.dart. (-5.84 points)

Analysis of lib/generator/common.dart reported 12 hints, including:

line 19 col 22: This function has a return type of 'String', but doesn't end with a return statement.

line 40 col 22: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 93 col 7: Don't explicitly initialize variables to null.

line 94 col 22: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 116 col 7: Don't explicitly initialize variables to null.

Fix lib/generator/reactive_preferences.dart. (-4.41 points)

Analysis of lib/generator/reactive_preferences.dart reported 9 hints, including:

line 34 col 79: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 67 col 34: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 79 col 35: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 85 col 44: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 98 col 52: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

Fix lib/generator/preferences.dart. (-1 points)

Analysis of lib/generator/preferences.dart reported 2 hints:

line 37 col 46: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

line 42 col 35: 'displayName' is deprecated and shouldn't be used. Use getDisplayString instead.

Maintenance suggestions

Package is getting outdated. (-52.05 points)

The package was last published 79 weeks ago.

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
build ^1.0.2 1.3.0
build_runner ^1.1.2 1.10.0
code_builder ^3.1.3 3.3.0
pref_gen_annotations ^0.0.1 0.0.2
source_gen ^0.9.3 0.9.5
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
args 1.6.0
async 2.4.2
build_config 0.4.2
build_daemon 2.1.4
build_resolvers 1.3.10
build_runner_core 5.2.0 6.0.0
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
checked_yaml 1.0.2
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
fixnum 0.10.11
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http_multi_server 2.2.0
http_parser 3.1.4
io 0.3.4
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
meta 1.2.1
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.1
pool 1.4.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
shelf 0.7.7
shelf_web_socket 0.2.3
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
stream_transform 1.2.0
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.2.0
watcher 0.9.7+15
web_socket_channel 1.1.0
yaml 2.2.1