mirror of
https://github.com/Iconica-Development/flutter_start.git
synced 2025-05-19 02:23:46 +02:00
Compare commits
22 commits
Author | SHA1 | Date | |
---|---|---|---|
|
87bf58e6e7 | ||
|
ada23abbc5 | ||
|
2c61f8d7db | ||
|
2a66e11611 | ||
0976083a9f | |||
6f24e0521d | |||
328a75b5a2 | |||
|
ed8b5b401a | ||
|
7635b8a4cc | ||
|
d0b0f88ad3 | ||
|
62161aa60b | ||
|
bf018a3ce6 | ||
|
c521be374d | ||
|
c558c8dbc7 | ||
|
c51c7de53a | ||
|
84e629d5b2 | ||
|
e7419bc8c1 | ||
|
90eb8119d8 | ||
|
fc65e98f96 | ||
|
07e1ad0990 | ||
|
e357f2fd0f | ||
bd1d6e5bf4 |
14 changed files with 220 additions and 156 deletions
14
.github/workflows/release.yml
vendored
Normal file
14
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
name: Iconica Standard Component Release Workflow
|
||||||
|
# Workflow Caller version: 1.0.0
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
call-global-iconica-workflow:
|
||||||
|
uses: Iconica-Development/.github/.github/workflows/component-release.yml@master
|
||||||
|
secrets: inherit
|
||||||
|
permissions: write-all
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -44,3 +44,7 @@ app.*.map.json
|
||||||
ios
|
ios
|
||||||
.metadata
|
.metadata
|
||||||
pubspec.lock
|
pubspec.lock
|
||||||
|
|
||||||
|
# FVM Version Cache
|
||||||
|
.fvm/
|
||||||
|
.fvmrc
|
||||||
|
|
22
CHANGELOG.md
22
CHANGELOG.md
|
@ -1,3 +1,25 @@
|
||||||
|
## 4.2.4
|
||||||
|
- Fixed the userstory to always call the splashScreenFuture and killswitchservice logic when a custom splashScreenBuilder is provided
|
||||||
|
|
||||||
|
## 4.2.3
|
||||||
|
- Added check if introduction should be shown according to the service before showing the introduction at all
|
||||||
|
|
||||||
|
## 4.2.2
|
||||||
|
- Added custom navigator in the root of the navigator user-story
|
||||||
|
|
||||||
|
## 4.2.1
|
||||||
|
- Updated flutter_introduction to 5.0.0
|
||||||
|
|
||||||
|
## 4.1.0
|
||||||
|
- Updated README
|
||||||
|
- Removed check if the introductions should be shown.
|
||||||
|
- Updated flutter_introduction to 3.1.0
|
||||||
|
|
||||||
|
## 4.0.0
|
||||||
|
- Added default introduction page.
|
||||||
|
- Added default splash screen.
|
||||||
|
- Changed the way the splash screen is enabled/disabled.
|
||||||
|
|
||||||
## 3.0.0
|
## 3.0.0
|
||||||
|
|
||||||
BREAKING:
|
BREAKING:
|
||||||
|
|
100
README.md
100
README.md
|
@ -6,60 +6,65 @@ Flutter_start is a package that allows you to jumpstart your application with a
|
||||||
|
|
||||||
To use this package, add flutter_start as a dependency in your pubspec.yaml file:
|
To use this package, add flutter_start as a dependency in your pubspec.yaml file:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
flutter_start:
|
flutter_start:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/Iconica-Development/flutter_start
|
url: https://github.com/Iconica-Development/flutter_start
|
||||||
ref: <Version>
|
ref: 4.1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
To use the module within your Flutter-application with predefined `Go_router` routes you should add the following:
|
## go_router
|
||||||
|
|
||||||
|
Add `go_router` as dependency to your project.
|
||||||
|
|
||||||
Add go_router as dependency to your project.
|
|
||||||
Add the following configuration to your flutter_application:
|
Add the following configuration to your flutter_application:
|
||||||
|
|
||||||
```
|
```
|
||||||
StartUserStoryConfiguration startUserStoryConfiguration = const StartUserStoryConfiguration();
|
List<GoRoute> getStartStoryRoutes() => getStartStoryRoutes();
|
||||||
```
|
```
|
||||||
|
|
||||||
and set the values as you wish.
|
Or with options:
|
||||||
|
|
||||||
Next add the `StartUserStoryConfiguration` to `getStartStoryRoutes` Like so:
|
Place the following code somewhere in your project where it can be accessed globally:
|
||||||
|
|
||||||
```
|
```
|
||||||
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
|
var startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||||
startUserStoryConfiguration,
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
List<GoRoute> getStartStoryRoutes() => getStartStoryRoutes(
|
||||||
|
configuration: startUserStoryConfiguration,
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally add the `getStartRoutes` to your `Go_router` routes like so:
|
Finally add the `getStartRoutes` to your `go_router` routes like so:
|
||||||
|
|
||||||
```
|
```
|
||||||
final GoRouter _router = GoRouter(
|
final GoRouter _router = GoRouter(
|
||||||
routes: <RouteBase>[
|
routes: <RouteBase>[
|
||||||
...getStartRoutes()
|
...getStartStoryRoutes()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
The routes that can be used to navigate are:
|
The routes that can be used to navigate are:
|
||||||
|
|
||||||
For routing to the `SplashScreen`:
|
For routing to the `splashScreen`:
|
||||||
|
|
||||||
```
|
```
|
||||||
static const String splashScreen = '/splashScreen';
|
static const String splashScreen = '/splashScreen';
|
||||||
```
|
```
|
||||||
|
|
||||||
For routing to the `Introduction`:
|
For routing to the `introduction`:
|
||||||
|
|
||||||
```
|
```
|
||||||
static const String introduction = '/introduction';
|
static const String introduction = '/introduction';
|
||||||
```
|
```
|
||||||
|
|
||||||
For routing to the `HomeEntry`:
|
For routing to the `home`:
|
||||||
|
|
||||||
```
|
```
|
||||||
static const String home = '/home';
|
static const String home = '/home';
|
||||||
```
|
```
|
||||||
|
|
||||||
If you don't want a SplashScreen in your application set your initialRoute to `Introduction`:
|
If you don't want a SplashScreen in your application set your initialRoute to `Introduction`:
|
||||||
|
@ -73,33 +78,64 @@ final GoRouter _router = GoRouter(
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
To use the module within your Flutter-application without predefined `Go_router` routes but with `Navigator` routes add the following :
|
## Navigator
|
||||||
|
|
||||||
Add the following configuration to your flutter_application:
|
|
||||||
|
|
||||||
|
Add the following code to the build-method of a chosen widget like so:
|
||||||
```
|
```
|
||||||
StartUserStoryConfiguration startUserStoryConfiguration = const StartUserStoryConfiguration();
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return NavigatorStartUserStory(
|
||||||
|
onComplete: (context) {},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Add the following code to the build-method of a chosen widget:
|
or with options:
|
||||||
|
|
||||||
|
Place the following code somewhere in your project where it can be accessed globally:
|
||||||
|
|
||||||
```
|
```
|
||||||
startNavigatorUserStory(startUserStoryConfiguration, context);
|
var startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||||
```
|
```
|
||||||
|
|
||||||
If the splashScreenBuilder is not used the SplashScreen will be skipped.
|
```
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return NavigatorStartUserStory(
|
||||||
|
configuration: startUserStoryConfiguration,
|
||||||
|
onComplete: (context) {},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The `StartUserStoryConfiguration` has its own parameters, as specified below:
|
The `StartUserStoryConfiguration` has its own parameters, as specified below:
|
||||||
| Parameter | Explanation |
|
| Parameter | Explanation |
|
||||||
|-----------|-------------|
|
|-----------|-------------|
|
||||||
| splashScreenBuilder | The builder for the splashScreen. |
|
| `splashScreenBuilder` | The builder to override the default splashScreen |
|
||||||
| introductionOptions | The options for the introduction. |
|
| `introductionBuilder` | A builder to wrap the introductions in your own page |
|
||||||
| introductionService | The service for the introduction. Default IntroductionService (SharedPreferencesIntroductionDataProvider()) |
|
| `introductionOptionsBuilder` | The builder to override the default `introductionOptions` |
|
||||||
| homeEntry | The widget that will be shown after the introduction. |
|
|`introductionService` | The service to override the default `introductionService` |
|
||||||
| introductionFallbackScreen | The widget that will be shown when the introduction is skipped. |
|
| `homeScreenRoute` | The route to navigate to after the introduction or splashScreen is completed |
|
||||||
| introductionScrollPhysics | The scrollPhysics for the introduction. |
|
| `introductionFallbackScreen` | The screen that is shown when something goes wrong fetching data for the introduction |
|
||||||
| showIntroduction | Whether or not the introduction should be shown. |
|
| `introductionScrollPhysics` | The scroll physics for the introduction |
|
||||||
| 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|
|
| `showIntroduction` | A boolean to show the introduction or not. Defaults to true |
|
||||||
|
| `useKillswitch` | A boolean to use the killswitch or not. Defaults to false |
|
||||||
|
| `minimumSplashScreenDuration` | The minimum duration the splashScreen should be shown. Defaults to 3 seconds |
|
||||||
|
| `splashScreenFuture` | The future to be completed before the splashScreen is completed |
|
||||||
|
| `splashScreenCenterWidget` | The widget to be shown in the center of the splashScreen |
|
||||||
|
| `splashScreenBackgroundColor` | The color of the splashScreen background. Defaults to Color(0xff212121) |
|
||||||
|
| `canPopFromIntroduction` | Allow popping from introduction, defaults to true. Defaults to true |
|
||||||
|
| `killswitchService` | The service to override the default killswitch service |
|
||||||
|
| `showSplashScreen` | A boolean to show the splashScreen or not. Defaults to true |
|
||||||
|
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
|
|
||||||
|
|
3
example/.gitignore
vendored
3
example/.gitignore
vendored
|
@ -31,6 +31,9 @@ migrate_working_dir/
|
||||||
.pub/
|
.pub/
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
# platforms
|
||||||
|
/web
|
||||||
|
|
||||||
# Symbolication related
|
# Symbolication related
|
||||||
app.*.symbols
|
app.*.symbols
|
||||||
|
|
||||||
|
|
16
example/README.md
Normal file
16
example/README.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# example
|
||||||
|
|
||||||
|
A new Flutter project.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
This project is a starting point for a Flutter application.
|
||||||
|
|
||||||
|
A few resources to get you started if this is your first Flutter project:
|
||||||
|
|
||||||
|
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||||
|
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||||
|
|
||||||
|
For help getting started with Flutter development, view the
|
||||||
|
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||||
|
samples, guidance on mobile development, and a full API reference.
|
|
@ -31,7 +31,7 @@ class Home extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
|
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
|
||||||
config,
|
configuration: config,
|
||||||
);
|
);
|
||||||
|
|
||||||
StartUserStoryConfiguration config = StartUserStoryConfiguration(
|
StartUserStoryConfiguration config = StartUserStoryConfiguration(
|
||||||
|
@ -39,38 +39,6 @@ StartUserStoryConfiguration config = StartUserStoryConfiguration(
|
||||||
splashScreenBuilder: (context, onFinish) => SplashScreen(
|
splashScreenBuilder: (context, onFinish) => SplashScreen(
|
||||||
onFinish: onFinish,
|
onFinish: onFinish,
|
||||||
),
|
),
|
||||||
introductionOptionsBuilder: (ctx) => IntroductionOptions(
|
|
||||||
pages: [
|
|
||||||
IntroductionPage(
|
|
||||||
title: const Text('First page'),
|
|
||||||
text: const Text('Wow a page'),
|
|
||||||
graphic: const FlutterLogo(),
|
|
||||||
),
|
|
||||||
IntroductionPage(
|
|
||||||
title: const Text('Second page'),
|
|
||||||
text: const Text('Another page'),
|
|
||||||
graphic: const FlutterLogo(),
|
|
||||||
),
|
|
||||||
IntroductionPage(
|
|
||||||
title: const Text('Third page'),
|
|
||||||
text: const Text('The final page of this app'),
|
|
||||||
graphic: const FlutterLogo(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
introductionTranslations: const IntroductionTranslations(
|
|
||||||
skipButton: 'Skip it!',
|
|
||||||
nextButton: 'Next',
|
|
||||||
previousButton: 'Previous',
|
|
||||||
finishButton: 'To the app!',
|
|
||||||
),
|
|
||||||
tapEnabled: true,
|
|
||||||
displayMode: IntroductionDisplayMode.multiPageHorizontal,
|
|
||||||
buttonMode: IntroductionScreenButtonMode.text,
|
|
||||||
indicatorMode: IndicatorMode.dash,
|
|
||||||
skippable: true,
|
|
||||||
buttonBuilder: (context, onPressed, child, type) =>
|
|
||||||
ElevatedButton(onPressed: onPressed, child: child),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
class SplashScreen extends StatefulWidget {
|
class SplashScreen extends StatefulWidget {
|
||||||
|
@ -114,17 +82,3 @@ class HomeEntry extends StatelessWidget {
|
||||||
body: const Center(child: Text('HomeEntry')),
|
body: const Center(child: Text('HomeEntry')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExampleIntroductionDataProvider
|
|
||||||
implements SharedPreferencesIntroductionDataProvider {
|
|
||||||
@override
|
|
||||||
String key = 'example';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> setCompleted({bool value = true}) async =>
|
|
||||||
// ignore: void_checks
|
|
||||||
false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> shouldShow() async => true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,10 +12,8 @@ dependencies:
|
||||||
flutter_start:
|
flutter_start:
|
||||||
path: ../
|
path: ../
|
||||||
flutter_introduction_shared_preferences:
|
flutter_introduction_shared_preferences:
|
||||||
git:
|
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
|
||||||
url: https://github.com/Iconica-Development/flutter_introduction
|
version: ^5.0.0
|
||||||
ref: 2.1.0
|
|
||||||
path: packages/flutter_introduction_shared_preferences
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
@ -20,9 +20,10 @@ class StartUserStoryConfiguration {
|
||||||
this.minimumSplashScreenDuration = 3,
|
this.minimumSplashScreenDuration = 3,
|
||||||
this.splashScreenFuture,
|
this.splashScreenFuture,
|
||||||
this.splashScreenCenterWidget,
|
this.splashScreenCenterWidget,
|
||||||
this.splashScreenBackgroundColor,
|
this.splashScreenBackgroundColor = const Color(0xff212121),
|
||||||
this.canPopFromIntroduction = true,
|
this.canPopFromIntroduction = true,
|
||||||
this.killswitchService,
|
this.killswitchService,
|
||||||
|
this.showSplashScreen = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// You can use this to build your own splash screen.
|
/// You can use this to build your own splash screen.
|
||||||
|
@ -68,9 +69,6 @@ class StartUserStoryConfiguration {
|
||||||
/// Allow popping from introduction, defaults to true
|
/// Allow popping from introduction, defaults to true
|
||||||
final bool canPopFromIntroduction;
|
final bool canPopFromIntroduction;
|
||||||
|
|
||||||
/// returns true if the userstory should start with the introduction screen
|
/// If the splash screen should be shown or not.
|
||||||
bool get startWithIntroScreen =>
|
final bool showSplashScreen;
|
||||||
splashScreenBuilder == null &&
|
|
||||||
splashScreenCenterWidget == null &&
|
|
||||||
splashScreenBackgroundColor == null;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,19 @@ import 'package:flutter_start/src/go_router.dart';
|
||||||
import 'package:flutter_start/src/models/start_configuration.dart';
|
import 'package:flutter_start/src/models/start_configuration.dart';
|
||||||
import 'package:flutter_start/src/routes.dart';
|
import 'package:flutter_start/src/routes.dart';
|
||||||
import 'package:flutter_start/src/services/killswitch_service.dart';
|
import 'package:flutter_start/src/services/killswitch_service.dart';
|
||||||
|
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
List<GoRoute> getStartStoryRoutes(
|
List<GoRoute> getStartStoryRoutes({
|
||||||
StartUserStoryConfiguration configuration,
|
StartUserStoryConfiguration? configuration =
|
||||||
) =>
|
const StartUserStoryConfiguration(),
|
||||||
|
}) =>
|
||||||
<GoRoute>[
|
<GoRoute>[
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: StartUserStoryRoutes.splashScreen,
|
path: StartUserStoryRoutes.splashScreen,
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
var go = context.go;
|
var go = context.go;
|
||||||
var isAllowedToPassThrough = false;
|
var isAllowedToPassThrough = false;
|
||||||
var introductionSeen = false;
|
|
||||||
String? routeAfterSplash;
|
String? routeAfterSplash;
|
||||||
Future<void> splashLoadingMethod() async {
|
Future<void> splashLoadingMethod() async {
|
||||||
await Future.wait<void>(
|
await Future.wait<void>(
|
||||||
|
@ -31,7 +31,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
Duration.zero,
|
Duration.zero,
|
||||||
() async {
|
() async {
|
||||||
if (configuration.useKillswitch) {
|
if (configuration!.useKillswitch) {
|
||||||
var killswitchService = configuration.killswitchService ??
|
var killswitchService = configuration.killswitchService ??
|
||||||
DefaultKillswitchService();
|
DefaultKillswitchService();
|
||||||
|
|
||||||
|
@ -39,11 +39,6 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
await killswitchService.isKillswitchActive();
|
await killswitchService.isKillswitchActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
var introService = configuration.introductionService ??
|
|
||||||
IntroductionService(
|
|
||||||
SharedPreferencesIntroductionDataProvider(),
|
|
||||||
);
|
|
||||||
introductionSeen = !await introService.shouldShow();
|
|
||||||
if (context.mounted)
|
if (context.mounted)
|
||||||
routeAfterSplash = await configuration.splashScreenFuture
|
routeAfterSplash = await configuration.splashScreenFuture
|
||||||
?.call(context) ??
|
?.call(context) ??
|
||||||
|
@ -52,7 +47,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
),
|
),
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
Duration(
|
Duration(
|
||||||
seconds: configuration.minimumSplashScreenDuration,
|
seconds: configuration!.minimumSplashScreenDuration,
|
||||||
),
|
),
|
||||||
() async {},
|
() async {},
|
||||||
),
|
),
|
||||||
|
@ -61,7 +56,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
|
|
||||||
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
||||||
|
|
||||||
if (!configuration.showIntroduction || introductionSeen) {
|
if ((!configuration.showIntroduction) && context.mounted) {
|
||||||
return go(
|
return go(
|
||||||
routeAfterSplash ?? StartUserStoryRoutes.home,
|
routeAfterSplash ?? StartUserStoryRoutes.home,
|
||||||
);
|
);
|
||||||
|
@ -69,7 +64,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
return go(StartUserStoryRoutes.introduction);
|
return go(StartUserStoryRoutes.introduction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.splashScreenBuilder == null) {
|
if (configuration!.splashScreenBuilder == null) {
|
||||||
unawaited(splashLoadingMethod());
|
unawaited(splashLoadingMethod());
|
||||||
}
|
}
|
||||||
return buildScreenWithoutTransition(
|
return buildScreenWithoutTransition(
|
||||||
|
@ -84,7 +79,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
body: Center(
|
body: Center(
|
||||||
child:
|
child:
|
||||||
configuration.splashScreenCenterWidget?.call(context) ??
|
configuration.splashScreenCenterWidget?.call(context) ??
|
||||||
const SizedBox.shrink(),
|
defaultSplashScreen(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -94,7 +89,7 @@ List<GoRoute> getStartStoryRoutes(
|
||||||
path: StartUserStoryRoutes.introduction,
|
path: StartUserStoryRoutes.introduction,
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
var introduction = Introduction(
|
var introduction = Introduction(
|
||||||
service: configuration.introductionService ??
|
service: configuration!.introductionService ??
|
||||||
IntroductionService(
|
IntroductionService(
|
||||||
SharedPreferencesIntroductionDataProvider(),
|
SharedPreferencesIntroductionDataProvider(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_start/flutter_start.dart';
|
import 'package:flutter_start/flutter_start.dart';
|
||||||
import 'package:flutter_start/src/services/killswitch_service.dart';
|
import 'package:flutter_start/src/services/killswitch_service.dart';
|
||||||
|
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
|
||||||
|
|
||||||
/// Initial screen of the user story.
|
/// Initial screen of the user story.
|
||||||
///
|
///
|
||||||
|
@ -18,13 +19,11 @@ class NavigatorStartUserStory extends StatelessWidget {
|
||||||
final void Function(BuildContext context) onComplete;
|
final void Function(BuildContext context) onComplete;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => Navigator(
|
||||||
if (configuration.showIntroduction) {
|
onGenerateInitialRoutes: (_, __) => [
|
||||||
return _introduction(configuration, context, onComplete);
|
_getInitialRoute(configuration, onComplete),
|
||||||
}
|
],
|
||||||
|
);
|
||||||
return _splashScreen(configuration, context, onComplete);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enter the start user story with the Navigator 1.0 API.
|
/// Enter the start user story with the Navigator 1.0 API.
|
||||||
|
@ -41,6 +40,15 @@ Future<void> startNavigatorUserStory(
|
||||||
StartUserStoryConfiguration configuration, {
|
StartUserStoryConfiguration configuration, {
|
||||||
required void Function(BuildContext context) onComplete,
|
required void Function(BuildContext context) onComplete,
|
||||||
}) async {
|
}) async {
|
||||||
|
var initialRoute = _getInitialRoute(configuration, onComplete);
|
||||||
|
|
||||||
|
await Navigator.of(context).push(initialRoute);
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialPageRoute<dynamic> _getInitialRoute(
|
||||||
|
StartUserStoryConfiguration configuration,
|
||||||
|
void Function(BuildContext context) onComplete,
|
||||||
|
) {
|
||||||
var initialRoute = MaterialPageRoute(
|
var initialRoute = MaterialPageRoute(
|
||||||
builder: (context) => _splashScreen(
|
builder: (context) => _splashScreen(
|
||||||
configuration,
|
configuration,
|
||||||
|
@ -49,7 +57,7 @@ Future<void> startNavigatorUserStory(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (configuration.startWithIntroScreen) {
|
if (!configuration.showSplashScreen && configuration.showIntroduction) {
|
||||||
initialRoute = MaterialPageRoute(
|
initialRoute = MaterialPageRoute(
|
||||||
builder: (context) => _introduction(
|
builder: (context) => _introduction(
|
||||||
configuration,
|
configuration,
|
||||||
|
@ -58,8 +66,7 @@ Future<void> startNavigatorUserStory(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return initialRoute;
|
||||||
await Navigator.of(context).push(initialRoute);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _splashScreen(
|
Widget _splashScreen(
|
||||||
|
@ -70,7 +77,6 @@ Widget _splashScreen(
|
||||||
var navigator = Navigator.of(context);
|
var navigator = Navigator.of(context);
|
||||||
|
|
||||||
var isAllowedToPassThrough = false;
|
var isAllowedToPassThrough = false;
|
||||||
var introductionSeen = false;
|
|
||||||
|
|
||||||
Future<void> splashHandler() async {
|
Future<void> splashHandler() async {
|
||||||
await Future.wait<void>(
|
await Future.wait<void>(
|
||||||
|
@ -86,12 +92,6 @@ Widget _splashScreen(
|
||||||
isAllowedToPassThrough =
|
isAllowedToPassThrough =
|
||||||
await killswitchService.isKillswitchActive();
|
await killswitchService.isKillswitchActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
var introService = configuration.introductionService ??
|
|
||||||
IntroductionService(
|
|
||||||
SharedPreferencesIntroductionDataProvider(),
|
|
||||||
);
|
|
||||||
introductionSeen = !await introService.shouldShow();
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
|
@ -104,34 +104,37 @@ Widget _splashScreen(
|
||||||
|
|
||||||
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
||||||
|
|
||||||
if ((!configuration.showIntroduction || introductionSeen) &&
|
var introService = configuration.introductionService ??
|
||||||
context.mounted) {
|
IntroductionService(SharedPreferencesIntroductionDataProvider());
|
||||||
onComplete(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.mounted) {
|
var shouldShowIntroduction =
|
||||||
await navigator.pushReplacement(
|
configuration.showIntroduction && await introService.shouldShow();
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => _introduction(
|
if (!context.mounted) return;
|
||||||
configuration,
|
|
||||||
context,
|
if (!shouldShowIntroduction) return onComplete(context);
|
||||||
onComplete,
|
|
||||||
),
|
await navigator.pushReplacement(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => _introduction(
|
||||||
|
configuration,
|
||||||
|
context,
|
||||||
|
onComplete,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unawaited(splashHandler());
|
||||||
|
|
||||||
var builder = configuration.splashScreenBuilder;
|
var builder = configuration.splashScreenBuilder;
|
||||||
|
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
unawaited(splashHandler());
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: configuration.splashScreenBackgroundColor,
|
backgroundColor: configuration.splashScreenBackgroundColor,
|
||||||
body: Center(
|
body: Center(
|
||||||
child: configuration.splashScreenCenterWidget?.call(context) ??
|
child: configuration.splashScreenCenterWidget?.call(context) ??
|
||||||
const SizedBox.shrink(),
|
defaultSplashScreen(context),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -158,8 +161,12 @@ Widget _introduction(
|
||||||
);
|
);
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: configuration.canPopFromIntroduction,
|
canPop: configuration.canPopFromIntroduction,
|
||||||
child: Scaffold(
|
child: configuration.introductionBuilder?.call(
|
||||||
body: introduction,
|
context,
|
||||||
),
|
introduction,
|
||||||
|
) ??
|
||||||
|
Scaffold(
|
||||||
|
body: introduction,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
6
lib/src/widgets/default_splash_screen.dart
Normal file
6
lib/src/widgets/default_splash_screen.dart
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
Text defaultSplashScreen(BuildContext context) => Text(
|
||||||
|
'iconinstagram',
|
||||||
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
|
);
|
25
pubspec.yaml
25
pubspec.yaml
|
@ -1,7 +1,8 @@
|
||||||
name: flutter_start
|
name: flutter_start
|
||||||
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
|
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
|
||||||
publish_to: "none"
|
version: 4.2.4
|
||||||
version: 3.0.0
|
|
||||||
|
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.2.5 <4.0.0"
|
sdk: ">=3.2.5 <4.0.0"
|
||||||
|
@ -9,20 +10,16 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ">=1.0.2 <2.0.0"
|
||||||
go_router: any
|
go_router: ">=14.2.0 <15.0.0"
|
||||||
http: any
|
http: ">=1.2.1 <2.0.0"
|
||||||
package_info_plus: any
|
package_info_plus: ">=8.0.0 <9.0.0"
|
||||||
flutter_introduction:
|
flutter_introduction:
|
||||||
git:
|
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub
|
||||||
url: https://github.com/Iconica-Development/flutter_introduction
|
version: ^5.0.0
|
||||||
ref: 2.1.0
|
|
||||||
path: packages/flutter_introduction
|
|
||||||
flutter_introduction_shared_preferences:
|
flutter_introduction_shared_preferences:
|
||||||
git:
|
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
|
||||||
url: https://github.com/Iconica-Development/flutter_introduction
|
version: ^5.0.0
|
||||||
ref: 2.1.0
|
|
||||||
path: packages/flutter_introduction_shared_preferences
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
14
test/_test.dart
Normal file
14
test/_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// This is an example unit test.
|
||||||
|
//
|
||||||
|
// A unit test tests a single function, method, or class. To learn more about
|
||||||
|
// writing unit tests, visit
|
||||||
|
// https://flutter.dev/docs/cookbook/testing/unit/introduction
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Plus Operator', () {
|
||||||
|
test('should add two numbers together', () {
|
||||||
|
expect(1 + 1, 2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue