add gitlab ci config
add logging, define context for login management
This commit is contained in:
parent
75e56819b8
commit
1b6f0b6a90
17
.gitlab-ci.yaml
Normal file
17
.gitlab-ci.yaml
Normal 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
|
53
lib/app.dart
53
lib/app.dart
@ -1,57 +1,62 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:openmediacentermobile/api/token.dart';
|
||||
import 'package:openmediacentermobile/login_screen.dart';
|
||||
import 'package:openmediacentermobile/token.dart';
|
||||
|
||||
import 'logincontext.dart';
|
||||
import 'video_feed.dart';
|
||||
|
||||
class App extends StatefulWidget {
|
||||
App({Key? key}) : super(key: key) {}
|
||||
|
||||
const App({Key? key}) : super(key: key);
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return AppState();
|
||||
}
|
||||
State<StatefulWidget> createState() => AppState();
|
||||
}
|
||||
|
||||
class AppState extends State<App> {
|
||||
String? loggedin = null;
|
||||
|
||||
onLogin() {
|
||||
setState(() {
|
||||
loggedin = "ddd";
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (loggedin == null) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (loggedin == "") {
|
||||
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(onLogin: onLogin)));
|
||||
body: LoginScreen()));
|
||||
} else {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Openmediacenter"),
|
||||
title: Row(
|
||||
children: [
|
||||
Text("Openmediacenter"),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
loginctx.onLoggin(false);
|
||||
},
|
||||
child: Text("logout"))
|
||||
],
|
||||
),
|
||||
),
|
||||
body: VideoFeed()));
|
||||
}
|
||||
}
|
||||
|
||||
AppState() {
|
||||
@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");
|
||||
setState(() {
|
||||
loggedin = value;
|
||||
});
|
||||
if (value != null && value != "") {
|
||||
loginctx.onLoggin(false);
|
||||
} else {
|
||||
loginctx.onLoggin(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'logincontext.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({Key? key, this.onLogin}) : super(key: key);
|
||||
|
||||
@ -13,6 +15,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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
56
lib/logincontext.dart
Normal 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;
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:openmediacentermobile/app.dart';
|
||||
import 'package:openmediacentermobile/logincontext.dart';
|
||||
|
||||
// main app entry point
|
||||
void main() {
|
||||
Logger().i("App init!");
|
||||
runApp(App());
|
||||
runApp(const LoginContainer(child: App()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user