2019-01-31 15:07:52 +01:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-31 15:07:52 +01:00
|
|
|
class NotificationProvider extends StatefulWidget {
|
|
|
|
final Widget child;
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-31 15:07:52 +01:00
|
|
|
NotificationProvider({@required this.child});
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-31 15:07:52 +01:00
|
|
|
static _NotificationProviderState of(BuildContext context) {
|
|
|
|
return (context.inheritFromWidgetOfExactType(_InheritedNotificationProvider)
|
|
|
|
as _InheritedNotificationProvider)
|
|
|
|
.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
_NotificationProviderState createState() => new _NotificationProviderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NotificationProviderState extends State<NotificationProvider> {
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCount(int value) {
|
|
|
|
setState(() {
|
|
|
|
count = value;
|
2019-01-23 09:50:51 +01:00
|
|
|
});
|
|
|
|
}
|
2019-01-31 15:07:52 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new _InheritedNotificationProvider(
|
|
|
|
data: this,
|
|
|
|
child: widget.child,
|
|
|
|
);
|
|
|
|
}
|
2019-01-23 09:50:51 +01:00
|
|
|
}
|
|
|
|
|
2019-01-31 15:07:52 +01:00
|
|
|
class _InheritedNotificationProvider extends InheritedWidget {
|
|
|
|
final _NotificationProviderState data;
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-31 15:07:52 +01:00
|
|
|
_InheritedNotificationProvider({
|
2019-01-23 09:50:51 +01:00
|
|
|
Key key,
|
2019-01-31 15:07:52 +01:00
|
|
|
@required this.data,
|
|
|
|
@required Widget child,
|
|
|
|
}) : super(key: key, child: child);
|
2019-01-23 09:50:51 +01:00
|
|
|
|
|
|
|
@override
|
2019-01-31 15:07:52 +01:00
|
|
|
bool updateShouldNotify(_InheritedNotificationProvider old) => true;
|
2019-01-23 09:50:51 +01:00
|
|
|
}
|