diff --git a/lib/main.dart b/lib/main.dart index 94dc3c41..d2a8d01d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:universal_html/html.dart' as html; import 'package:vrouter/vrouter.dart'; +import 'widgets/layouts/wait_for_login.dart'; import 'widgets/lock_screen.dart'; import 'widgets/matrix.dart'; import 'config/themes.dart'; @@ -126,7 +127,7 @@ class _FluffyChatAppState extends State { context: context, router: _router, testClient: widget.testClient, - child: child, + child: WaitForInitPage(child), ); }, ); diff --git a/lib/widgets/layouts/one_page_card.dart b/lib/widgets/layouts/one_page_card.dart index 1499c680..283f0dc5 100644 --- a/lib/widgets/layouts/one_page_card.dart +++ b/lib/widgets/layouts/one_page_card.dart @@ -41,7 +41,7 @@ class OnePageCard extends StatelessWidget { vertical: max((MediaQuery.of(context).size.height - 800) / 2, 12), ), - child: SafeArea(child: Card(child: child)), + child: SafeArea(child: Card(elevation: 7, child: child)), ), ); } diff --git a/lib/widgets/layouts/wait_for_login.dart b/lib/widgets/layouts/wait_for_login.dart new file mode 100644 index 00000000..480056af --- /dev/null +++ b/lib/widgets/layouts/wait_for_login.dart @@ -0,0 +1,24 @@ +import 'package:famedlysdk/famedlysdk.dart'; +import 'package:flutter/material.dart'; + +import '../matrix.dart'; + +class WaitForInitPage extends StatelessWidget { + final Widget page; + const WaitForInitPage(this.page, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + if (Matrix.of(context).loginState == null) { + return StreamBuilder( + stream: Matrix.of(context).client.onLoginStateChanged.stream, + builder: (context, snapshot) { + if (!snapshot.hasData) { + return Scaffold(body: Center(child: CircularProgressIndicator())); + } + return page; + }); + } + return page; + } +} diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 7df092cd..90faa1b5 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -266,8 +266,8 @@ class MatrixState extends State with WidgetsBindingObserver { utf8.decode((await http.get(Uri.parse('config.json'))).bodyBytes); final configJson = json.decode(configJsonString); AppConfig.loadFromJson(configJson); - } catch (e, s) { - Logs().v('[ConfigLoader] Failed to load config.json', e, s); + } catch (e, _) { + Logs().v('[ConfigLoader] config.json not found', e); } } @@ -326,8 +326,13 @@ class MatrixState extends State with WidgetsBindingObserver { onLoginStateChanged ??= client.onLoginStateChanged.stream.listen((state) { if (loginState != state) { loginState = state; - widget.router.currentState - .push(loginState == LoginState.logged ? '/rooms' : '/home'); + final isInLoginRoutes = {'/home', '/login', '/signup'} + .contains(widget.router.currentState.url); + if (widget.router.currentState.url == '/' || + (state == LoginState.logged) == isInLoginRoutes) { + widget.router.currentState + .push(loginState == LoginState.logged ? '/rooms' : '/home'); + } } });