swc_flutter 1.4.0 swc_flutter: ^1.4.0 copied to clipboard
flutter developement simplifier
State Widget Controller #
class CountState with ChangeNotifier {
int _value = 0;
increment() {
_value++;
notifyListeners();
}
int get() => _value;
}
class MyHomePage extends SwcStatelessWidget<MyHomePageController> {
getProviders() => [
ChangeNotifierProvider<CountState>(create: (_) => 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());
}
}