diff --git a/lib/src/app.dart b/lib/src/app.dart index 8253d14fc51e29f06d77c177df9e264c0bc951a9..7764940afa346024b194b17e65c7fba95ee14cff 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -85,6 +85,8 @@ class _MainAppState extends State<MainApp> { Screen _currentScreen = Screen.App; + bool _buttonsHidden = true; + @override initState() { super.initState(); @@ -101,13 +103,13 @@ class _MainAppState extends State<MainApp> { var token = json.decode(data.toString())["access_token"]; setScreen(Screen.App); - log("Open $_invokerURL"); try { await launch("$_invokerURL?token=$token&host=$_host"); } catch (e) { - log("Error launching url $_invokerURL"); + showErrorAlert(context, 'Unable to open URL $_invokerURL', openVereign); } + revealButtons(1); }, onError: (error) { log("Err $error"); @@ -121,20 +123,28 @@ class _MainAppState extends State<MainApp> { errorMessage.toLowerCase().contains("the operation couldn") ) { if (Platform.isAndroid) { - // Show only for android, because iOS will show the same alert as + // Reveal after three seconds + revealButtons(3); + + // Open only for android, because iOS will show the same alert as // was for Auth request openVereign(); } else { setScreen(Screen.App); + revealButtons(0); } } else { showErrorAlert(context, Platform.isAndroid ? errorDetails : errorMessage, openVereign); setScreen(Screen.App); + revealButtons(0); } }); initUniLinks(); + + // Show buttons after timeout + revealButtons(3); } @override @@ -153,6 +163,17 @@ class _MainAppState extends State<MainApp> { }); } + revealButtons(delay) { + Timer( + Duration(seconds: delay), + () { + setState(() { + _buttonsHidden = false; + }); + } + ); + } + handleLinkChange(Uri uri) { if (uri?.path == "/authorize") { setState(() { @@ -187,6 +208,11 @@ class _MainAppState extends State<MainApp> { return; } + // Hide buttons so they wont blink after we close or finish oauth + setState(() { + _buttonsHidden = true; + }); + setScreen(Screen.OAuth); var params = Config.getOAuthParams(host: _host); @@ -225,6 +251,7 @@ class _MainAppState extends State<MainApp> { setHost: setHost, openDashboardClick: openVereign, authorizeClick: startOAuth, + buttonsHidden: _buttonsHidden ) ); } diff --git a/lib/src/screens/home.dart b/lib/src/screens/home.dart index 6c4f085ac052cbe0c0f2aed44e953332e43af0db..c5e8e88309250d99b2cff53ade6c8efb6f5073dd 100644 --- a/lib/src/screens/home.dart +++ b/lib/src/screens/home.dart @@ -12,10 +12,12 @@ class Home extends StatefulWidget { @required this.setHost, @required this.authorizeClick, @required this.openDashboardClick, + @required this.buttonsHidden, }); final AppMode mode; final String host; + final bool buttonsHidden; final void Function(String) setHost; final void Function() openDashboardClick; final void Function() authorizeClick; @@ -25,25 +27,14 @@ class Home extends StatefulWidget { } class _HomeState extends State<Home> { - bool _hidden = true; - @override initState() { super.initState(); - - Timer( - Duration(seconds: 3), - () { - setState(() { - _hidden = false; - }); - } - ); } @override Widget build(BuildContext context) { - if (_hidden) { + if (widget.buttonsHidden) { return Scaffold(); }