Merge pull request #3 from Iconica-Development/feature/killswitch

feat: killswitch
This commit is contained in:
Gorter-dev 2024-01-24 16:57:50 +01:00 committed by GitHub
commit 68205013b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 124 additions and 8 deletions

View file

@ -99,3 +99,4 @@ The `StartUserStoryConfiguration` has its own parameters, as specified below:
| introductionFallbackScreen | The widget that will be shown when the introduction is skipped. |
| introductionScrollPhysics | The scrollPhysics for the introduction. |
| showIntroduction | Whether or not the introduction should be shown. |
| useKillswitch | Whether or not the killswitch should be used. This will only work when you use the splashScreen and you need to have a active internet connection|

View file

@ -261,6 +261,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.1"
http:
dependency: transitive
description:
name: http
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
url: "https://pub.dev"
source: hosted
version: "1.2.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
lints:
dependency: transitive
description:
@ -317,6 +333,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
package_info_plus:
dependency: transitive
description:
name: package_info_plus
sha256: "88bc797f44a94814f2213db1c9bd5badebafdfb8290ca9f78d4b9ee2a3db4d79"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:

View file

@ -11,6 +11,7 @@ class StartUserStoryConfiguration {
this.introductionFallbackScreen,
this.introductionScrollPhysics,
this.showIntroduction = true,
this.useKillswitch = false,
});
final Widget Function(
BuildContext context,
@ -24,4 +25,5 @@ class StartUserStoryConfiguration {
final IntroductionService? introductionService;
final ScrollPhysics? introductionScrollPhysics;
final bool? showIntroduction;
final bool? useKillswitch;
}

View file

@ -0,0 +1,29 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
class KillswitchService {
Future<bool> isKillswitchActive() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
var response = await http
.get(
Uri.parse('https://active-obelugnnza-uc.a.run.app/?appName=$appName'),
)
.timeout(
const Duration(seconds: 5),
onTimeout: () => http.Response('false', 500),
)
.onError(
(error, stackTrace) => http.Response('false', 500),
);
var decoded = jsonDecode(response.body);
if (decoded == true) {
return true;
}
return false;
}
}

View file

@ -8,6 +8,7 @@ import 'package:flutter_introduction_shared_preferences/flutter_introduction_sha
import 'package:flutter_start/src/go_router.dart';
import 'package:flutter_start/src/models/start_configuration.dart';
import 'package:flutter_start/src/routes.dart';
import 'package:flutter_start/src/services/killswitch_service.dart';
import 'package:go_router/go_router.dart';
@ -18,16 +19,24 @@ List<GoRoute> getStartStoryRoutes(
GoRoute(
path: StartUserStoryRoutes.splashScreen,
pageBuilder: (context, state) {
var go = context.go;
return buildScreenWithoutTransition(
context: context,
state: state,
child: configuration.splashScreenBuilder?.call(
context,
() {
if (configuration.showIntroduction == false) {
return context.go(StartUserStoryRoutes.home);
() async {
if (configuration.useKillswitch == true) {
var isActive =
await KillswitchService().isKillswitchActive();
if (!isActive) {
return;
}
}
return context.go(StartUserStoryRoutes.introduction);
if (configuration.showIntroduction == false) {
return go(StartUserStoryRoutes.home);
}
return go(StartUserStoryRoutes.introduction);
},
) ??
const Scaffold(

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_introduction_shared_preferences/flutter_introduction_shared_preferences.dart';
import 'package:flutter_start/flutter_start.dart';
import 'package:flutter_start/src/services/killswitch_service.dart';
Widget startNavigatorUserStory(
StartUserStoryConfiguration configuration, BuildContext context) {
@ -14,17 +15,25 @@ Widget _splashScreen(
StartUserStoryConfiguration configuration,
BuildContext context,
) {
var navigator = Navigator.of(context);
return configuration.splashScreenBuilder?.call(
context,
() {
() async {
bool isActive;
if (configuration.useKillswitch == true) {
isActive = await KillswitchService().isKillswitchActive();
if (!isActive) {
return () {};
}
}
if (configuration.showIntroduction == false) {
return Navigator.of(context).pushReplacement(
return navigator.pushReplacement(
MaterialPageRoute(
builder: (context) => _home(configuration, context),
),
);
}
return Navigator.of(context).pushReplacement(
return navigator.pushReplacement(
MaterialPageRoute(
builder: (context) => _introduction(configuration, context),
),

View file

@ -254,6 +254,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.1"
http:
dependency: "direct main"
description:
name: http
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
url: "https://pub.dev"
source: hosted
version: "1.2.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
lints:
dependency: transitive
description:
@ -310,6 +326,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
package_info_plus:
dependency: "direct main"
description:
name: package_info_plus
sha256: "88bc797f44a94814f2213db1c9bd5badebafdfb8290ca9f78d4b9ee2a3db4d79"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:

View file

@ -1,7 +1,7 @@
name: flutter_start
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
publish_to: "none"
version: 1.0.0
version: 1.1.0
environment:
sdk: ">=3.2.5 <4.0.0"
@ -21,6 +21,8 @@ dependencies:
ref: 2.0.0
path: packages/flutter_introduction_shared_preferences
go_router: ^13.0.1
http: ^1.2.0
package_info_plus: ^5.0.1
dev_dependencies:
flutter_test: