https://github.com/lesnitsky/lifecycle_widget
widget with lifecycle hooks for flutter
https://github.com/lesnitsky/lifecycle_widget
flutter flutter-lifecycle flutter-widget
Last synced: about 1 year ago
JSON representation
widget with lifecycle hooks for flutter
- Host: GitHub
- URL: https://github.com/lesnitsky/lifecycle_widget
- Owner: lesnitsky
- License: mit
- Created: 2020-09-16T22:55:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-28T17:08:34.000Z (over 5 years ago)
- Last Synced: 2025-03-29T15:51:07.631Z (over 1 year ago)
- Topics: flutter, flutter-lifecycle, flutter-widget
- Language: Dart
- Homepage: https://pub.dev/packages/lifecycle_widget
- Size: 149 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Lifecycle widget
Flutter widget with lifecycle methods
[](https://lesnitsky.dev?utm_source=lifecycle_widget)
[](https://github.com/lesnitsky/lifecycle_widget)
[](https://twitter.com/lesnitsky_dev)
## Installation
Add dependency to `pubspec.yaml`
```yaml
dependencies:
...
lifecycle_widget: ^1.0.0
```
Run in your terminal
```sh
flutter packages get
```
## Example
```dart
class TestWidget extends LifecycleWidget {
final int number;
const TestWidget({Key key, this.number}) : super(key: key);
void notify(BuildContext context, String text) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(text),
));
}
@override
void didMount(BuildContext context) {
notify(context, 'did mount');
super.didMount(context);
}
@override
void didUpdate(
BuildContext context,
covariant TestWidget oldWidget,
covariant TestWidget widget,
) {
notify(context, 'update ${oldWidget.number} => ${widget.number}');
super.didUpdate(context, oldWidget, widget);
}
@override
void willUnmount(BuildContext context) {
print('will unmount');
super.willUnmount(context);
}
@override
Widget build(BuildContext context) {
return Center(child: Text("number is $number"));
}
}
```
## License
MIT
[](https://lesnitsky.dev?utm_source=lifecycle_widget)
[](https://github.com/lesnitsky/lifecycle_widget)
[](https://twitter.com/lesnitsky_dev)