parent
19f613ce93
commit
00eb7808d8
@ -0,0 +1,56 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
|
||||||
|
typedef BoolSetter = Function(bool isSignedIn); |
||||||
|
|
||||||
|
class UserStoreImplementation extends StatefulWidget { |
||||||
|
final Widget child; |
||||||
|
const UserStoreImplementation({Key? key, required this.child}) |
||||||
|
: super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
_UserStoreImplementationState createState() => |
||||||
|
_UserStoreImplementationState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _UserStoreImplementationState extends State<UserStoreImplementation> { |
||||||
|
bool _isSignedIn = false; |
||||||
|
|
||||||
|
void _updateSignedIn(bool newValue) => setState( |
||||||
|
() { |
||||||
|
_isSignedIn = newValue; |
||||||
|
}, |
||||||
|
); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return UserStore( |
||||||
|
isSignedIn: _isSignedIn, |
||||||
|
setIsSignedIn: _updateSignedIn, |
||||||
|
child: widget.child, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class UserStore extends InheritedWidget { |
||||||
|
const UserStore({ |
||||||
|
Key? key, |
||||||
|
required this.isSignedIn, |
||||||
|
required this.setIsSignedIn, |
||||||
|
required Widget child, |
||||||
|
}) : super(key: key, child: child); |
||||||
|
|
||||||
|
final bool isSignedIn; |
||||||
|
final BoolSetter setIsSignedIn; |
||||||
|
|
||||||
|
static UserStore of(BuildContext context) { |
||||||
|
final UserStore? result = |
||||||
|
context.dependOnInheritedWidgetOfExactType<UserStore>(); |
||||||
|
assert(result != null, 'No UserStore found in context'); |
||||||
|
return result!; |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
bool updateShouldNotify(UserStore oldWidget) { |
||||||
|
return oldWidget.isSignedIn != isSignedIn; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue