From 51046aff1f86ab7a07c29951db305ef7bedb9fbf Mon Sep 17 00:00:00 2001 From: Joey Boerwinkel Date: Thu, 4 Apr 2024 09:41:31 +0200 Subject: [PATCH 1/3] refactor: rename myFunction in splashscreen function to splashHandler --- .../user_stories/flutter_start_userstory_navigator.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/user_stories/flutter_start_userstory_navigator.dart b/lib/src/user_stories/flutter_start_userstory_navigator.dart index 701a552..999a183 100644 --- a/lib/src/user_stories/flutter_start_userstory_navigator.dart +++ b/lib/src/user_stories/flutter_start_userstory_navigator.dart @@ -19,9 +19,11 @@ Widget _splashScreen( BuildContext context, ) { var navigator = Navigator.of(context); + var isAllowedToPassThrough = false; var introductionSeen = false; - Future myFunction() async { + + Future splashHandler() async { await Future.wait( [ configuration.splashScreenFuture?.call(context) ?? Future.value(), @@ -42,7 +44,6 @@ Widget _splashScreen( Duration( seconds: configuration.minimumSplashScreenDuration, ), - () async {}, ), ], ); @@ -65,7 +66,7 @@ Widget _splashScreen( return configuration.splashScreenBuilder?.call( context, - () async => myFunction(), + splashHandler, ) ?? Scaffold( backgroundColor: configuration.splashScreenBackgroundColor, From 6ecc2f0992987c1ee800dd94ed24614c9d1cf800 Mon Sep 17 00:00:00 2001 From: Joey Boerwinkel Date: Thu, 4 Apr 2024 09:45:15 +0200 Subject: [PATCH 2/3] fix: add mounted check to navigation after async gap for navigator version --- .../flutter_start_userstory_navigator.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/user_stories/flutter_start_userstory_navigator.dart b/lib/src/user_stories/flutter_start_userstory_navigator.dart index 999a183..bf8b819 100644 --- a/lib/src/user_stories/flutter_start_userstory_navigator.dart +++ b/lib/src/user_stories/flutter_start_userstory_navigator.dart @@ -50,18 +50,22 @@ Widget _splashScreen( if (configuration.useKillswitch && isAllowedToPassThrough) return; - if (!configuration.showIntroduction || introductionSeen) { + if ((!configuration.showIntroduction || introductionSeen) && + context.mounted) { await navigator.pushReplacement( MaterialPageRoute( builder: (context) => _home(configuration, context), ), ); } - await navigator.pushReplacement( - MaterialPageRoute( - builder: (context) => _introduction(configuration, context), - ), - ); + + if (context.mounted) { + await navigator.pushReplacement( + MaterialPageRoute( + builder: (context) => _introduction(configuration, context), + ), + ); + } } return configuration.splashScreenBuilder?.call( From 218ff31016196b30633f1e76f83acf544838eade Mon Sep 17 00:00:00 2001 From: Joey Boerwinkel Date: Thu, 4 Apr 2024 10:04:59 +0200 Subject: [PATCH 3/3] fix: call splash handler when no builder is provided The default splashscreen never proceeded to the next screen unless the splashHandler is being called --- .../flutter_start_userstory_navigator.dart | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/src/user_stories/flutter_start_userstory_navigator.dart b/lib/src/user_stories/flutter_start_userstory_navigator.dart index bf8b819..e3060c9 100644 --- a/lib/src/user_stories/flutter_start_userstory_navigator.dart +++ b/lib/src/user_stories/flutter_start_userstory_navigator.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter_start/flutter_start.dart'; import 'package:flutter_start/src/services/killswitch_service.dart'; @@ -68,17 +70,23 @@ Widget _splashScreen( } } - return configuration.splashScreenBuilder?.call( - context, - splashHandler, - ) ?? - Scaffold( - backgroundColor: configuration.splashScreenBackgroundColor, - body: Center( - child: configuration.splashScreenCenterWidget?.call(context) ?? - const SizedBox.shrink(), - ), - ); + var builder = configuration.splashScreenBuilder; + + if (builder == null) { + unawaited(splashHandler()); + return Scaffold( + backgroundColor: configuration.splashScreenBackgroundColor, + body: Center( + child: configuration.splashScreenCenterWidget?.call(context) ?? + const SizedBox.shrink(), + ), + ); + } + + return builder.call( + context, + splashHandler, + ); } Widget _introduction(