You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
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;
|
|
}
|
|
}
|
|
|