state_controller 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new51

state_controller

https://pub.dartlang.org/packages/state_controller

A new Flutter package.

About

This library is aimed at separating the logic of drawing a widget and changing its state. Please look at the example in the project.

Use StatefulWidget as a constructor, the widget is passed to the controller. A big request to use the methods of the life cycle controller.

Docs

StateController<T extends StatefulWidget>

'onCreate' called when creating a controller in 'initState()' of your state.

'onWidgetUpdate' called after changing the widget and before the method 'build()' of your state.

'onDispose' called when the 'dispose()' of your state.

'changeState' this method calls 'setState()' in itself, and therefore requires the same parameters.

ControllerInjector<W extends StatefulWidget, SC extends StateController<W>>

ControllerInjector is an mixin. For the status link and the controller, you must specify YourState with ControllerInjector and override method createStateController().

Example


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

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

class _MyHomePageState extends State<MyHomePage>
    with ControllerInjector<MyHomePage, _MyHomePageController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '${controller.counter}',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: controller.increment,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }

  @override
  _MyHomePageController createStateController() => _MyHomePageController();
}

class _MyHomePageController extends StateController<MyHomePage> {
  int _counter = 0;
  int get counter => _counter;

  void increment() {
    changeState(() {
      _counter++;
    });
  }
}

[0.1.1] - 29.11.2018

  • fix README for pub.dartlang.

[0.1.0] - 29.11.2018

  • Added more details in README.

[0.0.1] - 29.11.2018

  • Initial release.

example/lib/main.dart

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

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

class App extends StatelessWidget {
// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      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>
    with ControllerInjector<MyHomePage, _MyHomePageController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '${controller.counter}',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: controller.increment,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }

  @override
  _MyHomePageController createStateController() => _MyHomePageController();
}

class _MyHomePageController extends StateController<MyHomePage> {
  int _counter = 0;

  int get counter => _counter;

  @override
  void onCreate() {
    // TODO: implement onCreate
  }

  @override
  void onWidgetUpdate() {
    // TODO: implement onWidgetUpdate
  }

  void increment() {
    changeState(() {
      _counter++;
    });
  }

  @override
  void onDispose() {
    // TODO: implement onDispose
    super.onDispose();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  state_controller: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:state_controller/state_controller.dart';
  
Version Uploaded Documentation Archive
0.1.1 Nov 29, 2018 Go to the documentation of state_controller 0.1.1 Download state_controller 0.1.1 archive
0.1.0 Nov 29, 2018 Go to the documentation of state_controller 0.1.0 Download state_controller 0.1.0 archive
0.0.1 Nov 29, 2018 Go to the documentation of state_controller 0.0.1 Download state_controller 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
51
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test