Skip to content

muhammad369/state_controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

State Controller

pub package

Liked the way GetX manages state, but don't want to use a big framework that does everything? This simple package looks like GetX, wraps InheritedWidget and StreamBuilder, with no dependencies

// provide the controller in higher point of the widgets tree
StateProvider(
  controller: Controller(),
  view: MaterialApp(
    home: const MyHomePage(),
  )
)
// controller
class Controller extends StateController{
  Rx<int> counter = 0.obs;
  void increment() {
    counter.value++;
  }
}
// view
@override
Widget build(BuildContext context) {
  Controller controller = context.get();
  //
  return Scaffold(
    appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(title)),
    body: Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        const Text('You have pushed the button this many times:'),
        Obx(
          controller.counter,
          () => Text('${controller.counter.value}', style: Theme.of(context).textTheme.headlineMedium),
        ),
      ],
    ),
  ),
  floatingActionButton: FloatingActionButton(
    onPressed: controller.increment,
    tooltip: 'Increment',
    child: const Icon(Icons.add),
    ), 
  );
}

About

A Flutter state management package

Resources

License

Stars

Watchers

Forks

Packages

No packages published