scoped 1.0.0 copy "scoped: ^1.0.0" to clipboard
scoped: ^1.0.0 copied to clipboard

outdated

a pragmatic state management solution. comes with instance store (single, lazy & and scoped) and handy connectors

scoped #

A very pragmatic way to handle your state with one goal in mind:

Simplicity

Example

pubspec.yaml

dependencies:
  scoped: ^1.0.0

lib\main.dart

import 'package:scoped/scoped.dart';
//...

void main() => runApp(Scope(
  store:Store()
    ..add(Service('a great service')),
  child: YourApp()));

class Service {
  final String name;
  Service(this.name);
}

class YourApp extends StatelessWidget {
  Wiget build(BuildingContext context){
    return Bond<Service>(builder: (context, service)=> Text(service.name));
  }
}

with bonds

import 'package:scoped/scoped.dart';
//...

void main() => runApp(Scope(
  store:Store()
    ..add(Service('a great service')),
  child: YourApp()));

class Service extends Fluid {
  String _name;
  String name;
  set name(String value){
    _name = value;
    notify();
  }
  Service(String name):_name=name;
}

class YourApp extends StatelessWidget {
  Wiget build(BuildingContext context){
    return Column(
      children: [
        Bond<Service>(
          builder: (context, service) => Text(service.name)),
        FlatButton(
          child:Text("Change"),
          onPressed:() => Scope.get<Service>(context).name = 'changed')
      ]);
  }
}

with fluid models

import 'package:scoped/scoped.dart';
//...

void main() => runApp(Scope(
  store:Store()
    ..add(Service('a great service')),
  child: YourApp()));

class Service extends Fluid {
  String _name;
  String name;
  set name(String value){
    _name = value;
    notify();
  }
  Service(String name):_name=name;
}

class YourApp extends StatelessWidget {
  Wiget build(BuildingContext context){
    return Column(
      children: [
        FluidBuilder<Service>(
          fluid: Scope.get<Service>(context),
          builder: (context, s) => Text(s.name)),
        FlatButton(
          child:Text("Change"),
          onPressed:() => Scope.get<Service>(context).name = 'changed')
      ]);
  }
}
6
likes
0
pub points
10%
popularity

Publisher

verified publisherswipelab.co

a pragmatic state management solution. comes with instance store (single, lazy & and scoped) and handy connectors

Repository
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on scoped