lukas-heiligenbrunner
bf070ff99a
update dependencies try to infer the prefix of the server url display display size dependent amount on shuffle page
85 lines
1.9 KiB
Dart
85 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../api/token.dart';
|
|
import '../log/log.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;
|
|
bool _loading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
final token = Token.getInstance();
|
|
token.getToken().then((value) {
|
|
Log.i("The token value is $value");
|
|
if (value != null) {
|
|
setState(() {
|
|
_loggedIn = true;
|
|
_loading = false;
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_loggedIn = false;
|
|
_loading = false;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LoginContext(
|
|
loggedIn: _loggedIn,
|
|
child: _loading
|
|
? MaterialApp(
|
|
home: Container(
|
|
color: Colors.white,
|
|
child: const Center(child: CircularProgressIndicator()),
|
|
),
|
|
)
|
|
: 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;
|
|
|
|
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;
|
|
}
|
|
}
|