diff --git a/lib/api/token.dart b/lib/api/token.dart index 7365dca..966a4d3 100644 --- a/lib/api/token.dart +++ b/lib/api/token.dart @@ -2,12 +2,12 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:logger/logger.dart'; + +import '../log/log.dart'; class Token { static final Token _token = Token._(); final _storage = const FlutterSecureStorage(); - final _l = Logger(); String _tokenval = ""; @@ -16,7 +16,7 @@ class Token { } Future _readToken() async { - _l.d("reading token store"); + Log.d("reading token store"); WidgetsFlutterBinding.ensureInitialized(); return _storage.read(key: 'jwt'); } @@ -26,7 +26,13 @@ class Token { if (_tokenval == "") { final token = await _readToken(); - completer.complete(token); + // check if value is defined in phone store + if (token != null) { + completer.complete(token); + } else { + Log.d("no token defined"); + completer.complete(""); + } } else { completer.complete(_tokenval); } diff --git a/lib/log/log.dart b/lib/log/log.dart new file mode 100644 index 0000000..38b9cb4 --- /dev/null +++ b/lib/log/log.dart @@ -0,0 +1,38 @@ +import 'package:logger/logger.dart'; + +class Log { + static final _verbolg = Logger(); + static final _linelg = Logger( + printer: PrettyPrinter(methodCount: 0, printEmojis: false), + ); + + /// Log a message at level [Level.verbose]. + static void v(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _linelg.log(Level.verbose, message, error, stackTrace); + } + + /// Log a message at level [Level.debug]. + static void d(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _linelg.log(Level.debug, message, error, stackTrace); + } + + /// Log a message at level [Level.info]. + static void i(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _linelg.log(Level.info, message, error, stackTrace); + } + + /// Log a message at level [Level.warning]. + static void w(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _verbolg.log(Level.warning, message, error, stackTrace); + } + + /// Log a message at level [Level.error]. + static void e(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _verbolg.log(Level.error, message, error, stackTrace); + } + + /// Log a message at level [Level.wtf]. + static void wtf(dynamic message, [dynamic error, StackTrace? stackTrace]) { + _verbolg.log(Level.wtf, message, error, stackTrace); + } +} diff --git a/lib/login/logincontext.dart b/lib/login/logincontext.dart index e1c4f9a..1b96f4a 100644 --- a/lib/login/logincontext.dart +++ b/lib/login/logincontext.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:logger/logger.dart'; import '../api/token.dart'; +import '../log/log.dart'; class LoginContainer extends StatefulWidget { const LoginContainer({Key? key, required this.child}) : super(key: key); @@ -23,8 +23,8 @@ class _LoginContainerState extends State { final token = Token.getInstance(); token.getToken().then((value) { // todo this context call might occur before app rendered correctly! - Logger().i("The token value is $value"); - if (value != null && value != "") { + Log.i("The token value is $value"); + if (value != "") { setState(() { loggedIn = true; loading = false; @@ -43,8 +43,11 @@ class _LoginContainerState extends State { return LoginContext( LoggedIn: loggedIn, child: loading - ? const MaterialApp( - home: Center(child: CircularProgressIndicator()), + ? MaterialApp( + home: Container( + color: Colors.white, + child: const Center(child: CircularProgressIndicator()), + ), ) : widget.child, onLoggin: (bool login) { diff --git a/lib/main.dart b/lib/main.dart index 9937f51..ca8d9df 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:logger/logger.dart'; import 'package:openmediacentermobile/app.dart'; +import 'log/log.dart'; import 'login/logincontext.dart'; // main app entry point void main() { - Logger().i("App init!"); + Log.i("App init!"); runApp(const LoginContainer(child: App())); } diff --git a/lib/video_feed.dart b/lib/video_feed.dart index d0a77d4..19cd719 100644 --- a/lib/video_feed.dart +++ b/lib/video_feed.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; +import 'log/log.dart'; import 'preview_tile.dart'; class VideoFeed extends StatelessWidget { @@ -22,7 +22,7 @@ class VideoFeed extends StatelessWidget { crossAxisSpacing: 10), itemCount: _vids.length, itemBuilder: (context, index) { - print("item $index built!"); + Log.d("item $index built!"); return PreviewTile(dta: _vids[index]); }); }