OpenMediacenterMobileFlutter/lib/app.dart
lukas 1b6f0b6a90 add gitlab ci config
add logging, define context for login management
2021-12-10 18:36:59 +01:00

63 lines
1.7 KiB
Dart

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