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

outdated

flutter developement simplifier

State Widget Controller #

CI pub package codecov

class CountState with ChangeNotifier {

  int _value = 0;

  increment() {
    _value++;
    notifyListeners();
  }

  int get() => _value;

}
class MyHomePage extends SwcStatefulWidget {

  SwcState createState() => _MyHomePageState();

}

class _MyHomePageState extends SwcState<MyHomePage, MyHomePageController> {

  final  _countState = CountState();

  getProviders() => [
    ChangeNotifierProvider<CountState>.value(value: _countState),
  ];

  getController() => MyHomePageController();

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("counting using swc_flutter"),
      ),
      body: Center(
        child: Consumer<CountState>(builder: (context, state, _) {
          return Text(state.get().toString());
        }),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add_circle),
        onPressed: () => controller.onAddButtonClick(context),
      ),
    );
  }

}
class MyHomePageController extends SwcController {

  init(BuildContext context) {
    print("init my home page");
  }

  onAddButtonClick(BuildContext context) {
    dispatch(context, (CountState state) => state.increment());
  }
 
}