add gitlab ci config

add logging, define context for login management
This commit is contained in:
lukas 2021-12-10 18:36:59 +01:00
parent 75e56819b8
commit 1b6f0b6a90
6 changed files with 110 additions and 26 deletions

17
.gitlab-ci.yaml Normal file
View File

@ -0,0 +1,17 @@
image: cirrusci/flutter
stages:
- build
flutter_build_android: #Job name
stage: build # kind of job
before_script:
- flutter packages get
- flutter clean
script:
- flutter build apk
artifacts:
paths:
- build/app/outputs/apk/release/app-release.apk
tags:
- flutter

View File

@ -1,57 +1,62 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:openmediacentermobile/api/token.dart';
import 'package:openmediacentermobile/login_screen.dart'; import 'package:openmediacentermobile/login_screen.dart';
import 'package:openmediacentermobile/token.dart';
import 'logincontext.dart';
import 'video_feed.dart'; import 'video_feed.dart';
class App extends StatefulWidget { class App extends StatefulWidget {
App({Key? key}) : super(key: key) {} const App({Key? key}) : super(key: key);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() => AppState();
return AppState();
}
} }
class AppState extends State<App> { class AppState extends State<App> {
String? loggedin = null;
onLogin() {
setState(() {
loggedin = "ddd";
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (loggedin == null) { var loginctx = LoginContext.of(context);
return const CircularProgressIndicator();
} else if (loggedin == "") { Logger().d("We are logged in: ${loginctx.LoggedIn}");
if (!loginctx.LoggedIn) {
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Login"), title: const Text("Login"),
), ),
body: LoginScreen(onLogin: onLogin))); body: LoginScreen()));
} else { } else {
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Openmediacenter"), title: Row(
children: [
Text("Openmediacenter"),
ElevatedButton(
onPressed: () {
loginctx.onLoggin(false);
},
child: Text("logout"))
],
),
), ),
body: VideoFeed())); body: VideoFeed()));
} }
} }
AppState() { @override
void initState() {
final token = Token.getInstance(); final token = Token.getInstance();
token.getToken().then((value) { 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"); Logger().i("The token value is $value");
setState(() { if (value != null && value != "") {
loggedin = value; loginctx.onLoggin(false);
}); } else {
loginctx.onLoggin(true);
}
}); });
} }
} }

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'logincontext.dart';
class LoginScreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key, this.onLogin}) : super(key: key); const LoginScreen({Key? key, this.onLogin}) : super(key: key);
@ -13,6 +15,9 @@ class _LoginScreenState extends State<LoginScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: this.widget.onLogin, child: Text("klick meee")); onPressed: () {
LoginContext.of(context).onLoggin(true);
},
child: Text("klick meee"));
} }
} }

56
lib/logincontext.dart Normal file
View File

@ -0,0 +1,56 @@
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;
}
}

View File

@ -1,9 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:openmediacentermobile/app.dart'; import 'package:openmediacentermobile/app.dart';
import 'package:openmediacentermobile/logincontext.dart';
// main app entry point // main app entry point
void main() { void main() {
Logger().i("App init!"); Logger().i("App init!");
runApp(App()); runApp(const LoginContainer(child: App()));
} }