dime_flutter 0.4.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

Dime Flutter package #

Bringing Dime dependency injection to Flutter with usable helper methods and Widgets.

Getting Started #

Take a look at Dime package for BaseModules and definitions.

Use DimeScopeFlutter to wrap child widget with Dime Scope and provide list of modules for that scope. Root Scope modules are always fallback to. Use DimeFlutter.scopeOf(...) as inherit widget to fetch DimeScope to get instances you need down the tree.

Dime Scope fetch up the tree examples: #

Test class to be referenced by main scope_test.dart tests.

Modules:

ModuleInstance
ModuleAAA()
AB()
AC()
ModuleBBA()
BB()
BC()
ModuleCCA()
CB()
CC()
ModuleXXAA()
BB()
CC()

Scope graph:

Root ScopeModules/ScopesModules/ScopesModules/Scopes
Dime- ModuleC
- ModuleXX (override)
- scope1- ModuleA
- ModuleB
- scope2- ModuleA
- ModuleC
- scope 21- ModuleC
- scope 22- ModuleA
- ModuleB

Example injections:

scope2.inject<CA> - from scope2.ModuleC.CA

Dime.inject<CA> - from dime.ModuleC.CA

scope1.inject<CA> - from dime.ModuleC.CA

scope1.inject<AA> - from scope1.ModuleA.AA

scope2.inject<BC> - not found - can't access other scopes

scope2.inject<AB> - from scope2.ModuleA.AB

Dime.inject<AA> - dime.ModuleXX.AA

Dime.inject<AB> - not found - Dime can't drill to scopes

Dime.inject<CC> - dime.ModuleC.CC

scope21.inject<AA> - scope2.ModuleA.AA

scope21.inject<CC> - scope21.ModuleC.CC

scope22.inject<AC> - scope22.ModuleA.AC

scope22.inject<CB> - scope2.ModuleC.CB

scope21.inject<BB> - dime.ModuleX.BB

0.4.0 - Following dime versioning #

0.3.5 - Following dime versioning #

0.3.4 - Fix for single by tag injection #

0.3.3 - Update for Fimber 0.4 #

0.3.2 - Dime for Flutter #

  • Inherit widget for Dime Scope
  • DimeScopeFlutter Widget to wrap children with a scope
  • DimeFlutter Inherited widget to fetch last scope instance

0.3.1 - Publish errors fixes #

[0.0.1-dev] - Dime for Flutter widget #

  • initial Dime scope widget with dispose wrapper of StatefulWidget.

example/lib/main.dart

import 'package:dime_flutter/dime_flutter.dart';
import 'package:flutter/material.dart';

import 'di.dart';

void main(List<String> args) {
  runApp(DimeApp());
}

class DimeApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DimeScopeFlutter(
      scopeName: "myroot",
      modules: [
        ServiceModule(),
        UiModule(),
      ],
      child: MaterialApp(
        title: "Dime test App",
        theme: Theme.of(context).copyWith(primaryColor: Colors.amber),
        initialRoute: "/",
        routes: {"/": (ctx) => HomePage(), "/A": (_) => TestAPageScope()},
      ),
    );
  }
}

AppBar provideAppBar(BuildContext context) {
  var title = DimeFlutter.get<TitleService>(context).text;
  // it is better to wrap it with Theme object
  return AppBar(
    title: Text(title),
  );
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var theme =
        DimeFlutter.get<ThemeGenerator>(context).updateTheme(Theme.of(context));
    return Theme(
      data: theme,
      child: Scaffold(
        appBar: provideAppBar(context),
        body: Container(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Text("Home Page"),
              RaisedButton(
                child: Text("PAGE A"),
                onPressed: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (_) => TestAPageScope()));
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

class TestAPageScope extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DimeScopeFlutter(
        scopeName: "test-a",
        modules: [RedUiModule()..addSingle<TitleService>(TitlePageAService())],
        child: TestAPage());
  }
}

class TestAPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var theme =
        DimeFlutter.get<ThemeGenerator>(context).updateTheme(Theme.of(context));
    return Theme(
      data: theme,
      child: Scaffold(
        appBar: provideAppBar(context),
        body: Container(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Text("Test Page A"),
              RaisedButton(
                child: Text("PAGE A 1"),
                onPressed: () {},
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [dime_flutter] that is in a package requiring null.

Health issues and suggestions

Fix lib/flutter_scope.dart. (-5 points)

Analysis of lib/flutter_scope.dart reported 1 warning:

line 27 col 20: Parameters can't override default values, this method overrides 'Diagnosticable.toString' where 'minLevel' has a different value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dime ^0.4.0 0.4.0
fimber ^0.4.0 0.4.2
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test