OpenMediacenterMobileFlutter/lib/app.dart

63 lines
1.7 KiB
Dart
Raw Normal View History

2021-12-10 10:40:20 +00:00
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:openmediacentermobile/api/token.dart';
2021-12-10 10:40:20 +00:00
import 'package:openmediacentermobile/login_screen.dart';
import 'logincontext.dart';
2021-12-10 10:40:20 +00:00
import 'video_feed.dart';
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
2021-12-10 10:40:20 +00:00
@override
State<StatefulWidget> createState() => AppState();
2021-12-10 10:40:20 +00:00
}
class AppState extends State<App> {
@override
Widget build(BuildContext context) {
var loginctx = LoginContext.of(context);
Logger().d("We are logged in: ${loginctx.LoggedIn}");
if (!loginctx.LoggedIn) {
2021-12-10 10:40:20 +00:00
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Login"),
),
body: LoginScreen()));
2021-12-10 10:40:20 +00:00
} else {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Row(
children: [
Text("Openmediacenter"),
ElevatedButton(
onPressed: () {
loginctx.onLoggin(false);
},
child: Text("logout"))
],
),
2021-12-10 10:40:20 +00:00
),
body: VideoFeed()));
}
}
@override
void initState() {
2021-12-10 10:40:20 +00:00
final token = Token.getInstance();
token.getToken().then((value) {
// todo this context call might occur before app rendered correctly!
final loginctx = LoginContext.of(context);
2021-12-10 10:40:20 +00:00
Logger().i("The token value is $value");
if (value != null && value != "") {
loginctx.onLoggin(false);
} else {
loginctx.onLoggin(true);
}
2021-12-10 10:40:20 +00:00
});
}
}