From 077556d53d6e93246493808836686c8f379e1b93 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:57:06 +0200 Subject: [PATCH 1/2] refactoring initial route --- .../home_widget_navigate_processor.dart | 9 +-- lib/views/splash_screen/splash_screen.dart | 73 +++---------------- 2 files changed, 15 insertions(+), 67 deletions(-) diff --git a/lib/processors/scheme_processors/navigation_scheme_processors/home_widget_navigate_processor.dart b/lib/processors/scheme_processors/navigation_scheme_processors/home_widget_navigate_processor.dart index 591034229..ee2279cbc 100644 --- a/lib/processors/scheme_processors/navigation_scheme_processors/home_widget_navigate_processor.dart +++ b/lib/processors/scheme_processors/navigation_scheme_processors/home_widget_navigate_processor.dart @@ -4,7 +4,6 @@ import '../../../utils/home_widget_utils.dart'; import '../../../utils/logger.dart'; import '../../../utils/riverpod_providers.dart'; import '../../../views/link_home_widget_view/link_home_widget_view.dart'; -import '../../../views/splash_screen/splash_screen.dart'; import 'navigation_scheme_processor_interface.dart'; class HomeWidgetNavigateProcessor implements NavigationSchemeProcessor { @@ -42,15 +41,13 @@ class HomeWidgetNavigateProcessor implements NavigationSchemeProcessor { return; } if (fromInit) { - SplashScreen.setInitialView( - LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!), + Navigator.of(context).push( + MaterialPageRoute(builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!)), ); } else { Navigator.popUntil(context, (route) => route.isFirst); Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!), - ), + MaterialPageRoute(builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!)), ); } } diff --git a/lib/views/splash_screen/splash_screen.dart b/lib/views/splash_screen/splash_screen.dart index 8faf12e7f..8ad684bfc 100644 --- a/lib/views/splash_screen/splash_screen.dart +++ b/lib/views/splash_screen/splash_screen.dart @@ -12,27 +12,10 @@ import '../view_interface.dart'; class SplashScreen extends ConsumerStatefulWidget { static const routeName = '/'; - static Widget? _initialView; - static bool didNavigated = false; - final ApplicationCustomization customization; - const SplashScreen({required this.customization, super.key}); - @override ConsumerState createState() => _SplashScreenState(); - - static void setInitialView(Widget initialView) { - if (_initialView != null) { - Logger.warning('Initial view is already set. Ignoring new initial view: $initialView', name: 'splash_screen.dart#setInitialView'); - return; - } - if (didNavigated) { - Logger.warning('Splashscreen already navigated. Ignoring new initial view: $initialView', name: 'splash_screen.dart#setInitialView'); - return; - } - _initialView = initialView; - } } class _SplashScreenState extends ConsumerState { @@ -53,11 +36,8 @@ class _SplashScreenState extends ConsumerState { Logger.info('Starting app.', name: 'main.dart#initState'); Future.delayed(_splashScreenDelay, () { - if (mounted) { - setState(() { - _appIconIsVisible = true; - }); - } + if (mounted) setState(() => _appIconIsVisible = true); + Future.wait( [ Future.delayed(_splashScreenDuration), @@ -87,29 +67,7 @@ class _SplashScreenState extends ConsumerState { super.dispose(); } - Future _navigate() async { - SplashScreen.didNavigated = true; - if (SplashScreen._initialView != null) { - await Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (_, __, ___) => SplashScreen._initialView!, - transitionDuration: _splashScreenDuration, - transitionsBuilder: (_, a, __, view) => FadeTransition( - opacity: CurvedAnimation( - curve: const Interval(0, 1, curve: Curves.easeOut), - parent: a, - ), - child: view, - ), - ), - ); - } - if (!mounted) return; - _pushReplace(); - } - - void _pushReplace() { + void _navigate() async { if (_customization.disabledFeatures.isNotEmpty) { Logger.info('Disabled features: ${_customization.disabledFeatures}', name: 'main.dart#_pushReplace'); } @@ -118,22 +76,15 @@ class _SplashScreenState extends ConsumerState { appIcon: _customization.appIcon, disablePatchNotes: _customization.disabledFeatures.contains(AppFeature.patchNotes), ); - final routeBuilder = SplashScreen._initialView == null - ? PageRouteBuilder( - pageBuilder: (_, __, ___) => nextView, - transitionDuration: _splashScreenDuration, - settings: nextView.routeSettings, - transitionsBuilder: (_, a, __, view) => FadeTransition( - opacity: CurvedAnimation( - curve: const Interval(0, 1, curve: Curves.easeOut), - parent: a, - ), - child: view, - ), - ) - : PageRouteBuilder( - pageBuilder: (_, __, ___) => nextView, - ); + final routeBuilder = PageRouteBuilder(pageBuilder: (_, __, ___) => nextView); + // Idle until the splash screen is the top route. + // By default it is the top route, but it can be overridden by pushing a new route before initializing the app, e.g. by a deep link. + await Future.doWhile(() async { + await Future.delayed(const Duration(milliseconds: 100)); + if (!mounted) return false; + return (ModalRoute.of(context)?.isCurrent == false); + }); + if (!mounted) return; Navigator.of(context).popUntil((route) => route.isFirst); Navigator.pushReplacement(context, routeBuilder); } From 68c419de789de9e9dd2133b015fadbbd6a237370 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:00:14 +0200 Subject: [PATCH 2/2] QR-scanned token conflict resolving --- lib/state_notifiers/token_notifier.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/state_notifiers/token_notifier.dart b/lib/state_notifiers/token_notifier.dart index da23d6782..1396bc4cb 100644 --- a/lib/state_notifiers/token_notifier.dart +++ b/lib/state_notifiers/token_notifier.dart @@ -701,8 +701,8 @@ class TokenNotifier extends StateNotifier { Future> _tokensFromUri(Uri uri) async { try { final results = await TokenImportSchemeProcessor.processUriByAny(uri); - // final anyConflict = tokens.any((newToken) => state.tokens.any((stateToken) => stateToken.sameValuesAs(newToken))); - if (results != null && results.length > 1) { + if (results != null && (results.length > 1 || state.tokens.any((e) => results.first.asSuccess?.resultData.isSameTokenAs(e) == true))) { + Navigator.of(globalNavigatorKey.currentContext!).popUntil((route) => route.isFirst); final tokensToKeep = await Navigator.of(globalNavigatorKey.currentContext!).push>( MaterialPageRoute>( builder: (context) => ImportPlainTokensPage(