57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
class LoginContainer extends StatefulWidget {
|
||
|
const LoginContainer({Key? key, required this.child}) : super(key: key);
|
||
|
final Widget child;
|
||
|
|
||
|
@override
|
||
|
_LoginContainerState createState() => _LoginContainerState();
|
||
|
}
|
||
|
|
||
|
class _LoginContainerState extends State<LoginContainer> {
|
||
|
bool loggedIn = false;
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return LoginContext(
|
||
|
LoggedIn: loggedIn,
|
||
|
child: widget.child,
|
||
|
onLoggin: (bool login) {
|
||
|
if (loggedIn != login) {
|
||
|
setState(() {
|
||
|
loggedIn = login;
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class LoginContext extends InheritedWidget {
|
||
|
const LoginContext(
|
||
|
{Key? key,
|
||
|
required Widget child,
|
||
|
required this.LoggedIn,
|
||
|
required this.onLoggin})
|
||
|
: super(key: key, child: child);
|
||
|
|
||
|
final bool LoggedIn;
|
||
|
final void Function(bool) onLoggin;
|
||
|
|
||
|
setLoggedIn(bool login) {
|
||
|
onLoggin(login);
|
||
|
}
|
||
|
|
||
|
static LoginContext of(BuildContext context) {
|
||
|
final LoginContext? result =
|
||
|
context.dependOnInheritedWidgetOfExactType<LoginContext>();
|
||
|
assert(result != null, 'No LoginContext found in context');
|
||
|
return result!;
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
bool updateShouldNotify(LoginContext old) {
|
||
|
return LoggedIn != old.LoggedIn;
|
||
|
}
|
||
|
}
|