Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sbntt/swc_flutter


https://github.com/sbntt/swc_flutter

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# State Widget Controller

![CI](https://github.com/SBNTT/swc_flutter/workflows/CI/badge.svg)
[![pub package](https://img.shields.io/pub/v/swc_flutter.svg)](https://pub.dev/packages/swc_flutter)
[![codecov](https://codecov.io/gh/SBNTT/swc_flutter/branch/master/graph/badge.svg)](https://codecov.io/gh/SBNTT/swc_flutter)

```dart
class CountState with ChangeNotifier {

int _value = 0;

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

int get() => _value;

}
```

```dart
class MyHomePage extends SwcStatelessWidget {

@override
getProviders() => [
ChangeNotifierProvider(create: (_) => CountState()),
];

@override
getController() => MyHomePageController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('swc_flutter example app'),
),
body: Center(
child: Consumer(builder: (context, state, _) {
return Text(state.get().toString());
}),
),
floatingActionButton: FloatingActionButton(
onPressed: () => controller.onAddButtonClick(context),
child: const Icon(Icons.add),
),
);
}

}
```

```dart
class MyHomePageController extends SwcController {

@override
init(BuildContext context) {
// ignore: avoid_print
print('init my home page');
}

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

}
```