mirror of
https://github.com/Iconica-Development/flutter_start.git
synced 2025-05-18 18:13:45 +02:00
feat: add parameter to configuration to supply an implementation of the killswitch service
This commit is contained in:
parent
c9bc617ed0
commit
346f40435f
4 changed files with 23 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_introduction/flutter_introduction.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
|
/// An immutable class that represents the configuration for
|
||||||
/// starting a user story.
|
/// starting a user story.
|
||||||
|
@ -22,6 +23,7 @@ class StartUserStoryConfiguration {
|
||||||
this.splashScreenCenterWidget,
|
this.splashScreenCenterWidget,
|
||||||
this.splashScreenBackgroundColor,
|
this.splashScreenBackgroundColor,
|
||||||
this.canPopFromIntroduction = true,
|
this.canPopFromIntroduction = true,
|
||||||
|
this.killswitchService,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// You can use this to build your own splash screen.
|
/// You can use this to build your own splash screen.
|
||||||
|
@ -45,6 +47,7 @@ class StartUserStoryConfiguration {
|
||||||
introductionOptionsBuilder;
|
introductionOptionsBuilder;
|
||||||
final Widget? introductionFallbackScreen;
|
final Widget? introductionFallbackScreen;
|
||||||
final IntroductionService? introductionService;
|
final IntroductionService? introductionService;
|
||||||
|
final KillswitchService? killswitchService;
|
||||||
final ScrollPhysics? introductionScrollPhysics;
|
final ScrollPhysics? introductionScrollPhysics;
|
||||||
|
|
||||||
/// If the introduction should be shown.
|
/// If the introduction should be shown.
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:http/http.dart' as http;
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
/// A service class to check if a killswitch is active for the current app.
|
/// 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.
|
/// Checks if the killswitch is active for the current app.
|
||||||
///
|
///
|
||||||
/// It makes a GET request to a specific URL with the 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,
|
/// Returns a [Future] that completes with 'true' if the killswitch is active,
|
||||||
/// and 'false' otherwise.
|
/// and 'false' otherwise.
|
||||||
|
Future<bool> isKillswitchActive() => throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultKillswitchService implements KillswitchService {
|
||||||
|
@override
|
||||||
Future<bool> isKillswitchActive() async {
|
Future<bool> isKillswitchActive() async {
|
||||||
var packageInfo = await PackageInfo.fromPlatform();
|
var packageInfo = await PackageInfo.fromPlatform();
|
||||||
var appName = packageInfo.appName;
|
var appName = packageInfo.appName;
|
||||||
|
|
|
@ -31,9 +31,14 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
Duration.zero,
|
Duration.zero,
|
||||||
() async {
|
() async {
|
||||||
if (configuration.useKillswitch)
|
if (configuration.useKillswitch) {
|
||||||
|
var killswitchService = configuration.killswitchService ??
|
||||||
|
DefaultKillswitchService();
|
||||||
|
|
||||||
isAllowedToPassThrough =
|
isAllowedToPassThrough =
|
||||||
await KillswitchService().isKillswitchActive();
|
await killswitchService.isKillswitchActive();
|
||||||
|
}
|
||||||
|
|
||||||
var introService = configuration.introductionService ??
|
var introService = configuration.introductionService ??
|
||||||
IntroductionService(
|
IntroductionService(
|
||||||
SharedPreferencesIntroductionDataProvider(),
|
SharedPreferencesIntroductionDataProvider(),
|
||||||
|
|
|
@ -28,9 +28,14 @@ Widget _splashScreen(
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
Duration.zero,
|
Duration.zero,
|
||||||
() async {
|
() async {
|
||||||
if (configuration.useKillswitch)
|
if (configuration.useKillswitch) {
|
||||||
|
var killswitchService =
|
||||||
|
configuration.killswitchService ?? DefaultKillswitchService();
|
||||||
|
|
||||||
isAllowedToPassThrough =
|
isAllowedToPassThrough =
|
||||||
await KillswitchService().isKillswitchActive();
|
await killswitchService.isKillswitchActive();
|
||||||
|
}
|
||||||
|
|
||||||
var introService = configuration.introductionService ??
|
var introService = configuration.introductionService ??
|
||||||
IntroductionService(
|
IntroductionService(
|
||||||
SharedPreferencesIntroductionDataProvider(),
|
SharedPreferencesIntroductionDataProvider(),
|
||||||
|
|
Loading…
Reference in a new issue