diff --git a/lib/src/models/start_configuration.dart b/lib/src/models/start_configuration.dart index 87533f5..b2f4287 100644 --- a/lib/src/models/start_configuration.dart +++ b/lib/src/models/start_configuration.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_introduction/flutter_introduction.dart'; +import 'package:flutter_start/src/services/killswitch_service.dart'; /// An immutable class that represents the configuration for /// starting a user story. @@ -22,6 +23,7 @@ class StartUserStoryConfiguration { this.splashScreenCenterWidget, this.splashScreenBackgroundColor, this.canPopFromIntroduction = true, + this.killswitchService, }); /// You can use this to build your own splash screen. @@ -45,6 +47,7 @@ class StartUserStoryConfiguration { introductionOptionsBuilder; final Widget? introductionFallbackScreen; final IntroductionService? introductionService; + final KillswitchService? killswitchService; final ScrollPhysics? introductionScrollPhysics; /// If the introduction should be shown. diff --git a/lib/src/services/killswitch_service.dart b/lib/src/services/killswitch_service.dart index 3b0cd01..58ac99d 100644 --- a/lib/src/services/killswitch_service.dart +++ b/lib/src/services/killswitch_service.dart @@ -4,7 +4,7 @@ import 'package:http/http.dart' as http; import 'package:package_info_plus/package_info_plus.dart'; /// A service class to check if a killswitch is active for the current app. -class KillswitchService { +abstract interface class KillswitchService { /// Checks if the killswitch is active for the current app. /// /// It makes a GET request to a specific URL with the app @@ -14,6 +14,11 @@ class KillswitchService { /// /// Returns a [Future] that completes with 'true' if the killswitch is active, /// and 'false' otherwise. + Future isKillswitchActive() => throw UnimplementedError(); +} + +class DefaultKillswitchService implements KillswitchService { + @override Future isKillswitchActive() async { var packageInfo = await PackageInfo.fromPlatform(); var appName = packageInfo.appName; diff --git a/lib/src/user_stories/flutter_start_userstory_go_router.dart b/lib/src/user_stories/flutter_start_userstory_go_router.dart index 8661a9e..23c367e 100644 --- a/lib/src/user_stories/flutter_start_userstory_go_router.dart +++ b/lib/src/user_stories/flutter_start_userstory_go_router.dart @@ -31,9 +31,14 @@ List getStartStoryRoutes( Future.delayed( Duration.zero, () async { - if (configuration.useKillswitch) + if (configuration.useKillswitch) { + var killswitchService = configuration.killswitchService ?? + DefaultKillswitchService(); + isAllowedToPassThrough = - await KillswitchService().isKillswitchActive(); + await killswitchService.isKillswitchActive(); + } + var introService = configuration.introductionService ?? IntroductionService( SharedPreferencesIntroductionDataProvider(), diff --git a/lib/src/user_stories/flutter_start_userstory_navigator.dart b/lib/src/user_stories/flutter_start_userstory_navigator.dart index 701a552..2ef916a 100644 --- a/lib/src/user_stories/flutter_start_userstory_navigator.dart +++ b/lib/src/user_stories/flutter_start_userstory_navigator.dart @@ -28,9 +28,14 @@ Widget _splashScreen( Future.delayed( Duration.zero, () async { - if (configuration.useKillswitch) + if (configuration.useKillswitch) { + var killswitchService = + configuration.killswitchService ?? DefaultKillswitchService(); + isAllowedToPassThrough = - await KillswitchService().isKillswitchActive(); + await killswitchService.isKillswitchActive(); + } + var introService = configuration.introductionService ?? IntroductionService( SharedPreferencesIntroductionDataProvider(),