2021-12-10 10:40:20 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:logger/logger.dart';
|
2021-12-10 17:36:59 +00:00
|
|
|
import 'package:openmediacentermobile/api/token.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
import 'package:openmediacentermobile/login_screen.dart';
|
|
|
|
|
2021-12-10 17:36:59 +00:00
|
|
|
import 'logincontext.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
import 'video_feed.dart';
|
|
|
|
|
|
|
|
class App extends StatefulWidget {
|
2021-12-10 17:36:59 +00:00
|
|
|
const App({Key? key}) : super(key: key);
|
2021-12-10 10:40:20 +00:00
|
|
|
@override
|
2021-12-10 17:36:59 +00:00
|
|
|
State<StatefulWidget> createState() => AppState();
|
2021-12-10 10:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AppState extends State<App> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-12-10 17:36:59 +00:00
|
|
|
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"),
|
|
|
|
),
|
2021-12-10 17:36:59 +00:00
|
|
|
body: LoginScreen()));
|
2021-12-10 10:40:20 +00:00
|
|
|
} else {
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-12-10 17:36:59 +00:00
|
|
|
title: Row(
|
|
|
|
children: [
|
|
|
|
Text("Openmediacenter"),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () {
|
|
|
|
loginctx.onLoggin(false);
|
|
|
|
},
|
|
|
|
child: Text("logout"))
|
|
|
|
],
|
|
|
|
),
|
2021-12-10 10:40:20 +00:00
|
|
|
),
|
|
|
|
body: VideoFeed()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 17:36:59 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2021-12-10 10:40:20 +00:00
|
|
|
final token = Token.getInstance();
|
|
|
|
token.getToken().then((value) {
|
2021-12-10 17:36:59 +00:00
|
|
|
// 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");
|
2021-12-10 17:36:59 +00:00
|
|
|
if (value != null && value != "") {
|
|
|
|
loginctx.onLoggin(false);
|
|
|
|
} else {
|
|
|
|
loginctx.onLoggin(true);
|
|
|
|
}
|
2021-12-10 10:40:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|