feat: add parameter to configuration to supply an implementation of the killswitch service

This commit is contained in:
Joey Boerwinkel 2024-04-04 11:33:12 +02:00
parent c9bc617ed0
commit 346f40435f
4 changed files with 23 additions and 5 deletions

View file

@ -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.

View file

@ -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<bool> isKillswitchActive() => throw UnimplementedError();
}
class DefaultKillswitchService implements KillswitchService {
@override
Future<bool> isKillswitchActive() async {
var packageInfo = await PackageInfo.fromPlatform();
var appName = packageInfo.appName;

View file

@ -31,9 +31,14 @@ List<GoRoute> 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(),

View file

@ -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(),