mirror of
https://github.com/Iconica-Development/flutter_start.git
synced 2025-05-19 10:33:45 +02:00
Compare commits
No commits in common. "master" and "4.0.0" have entirely different histories.
13 changed files with 155 additions and 191 deletions
14
.github/workflows/release.yml
vendored
14
.github/workflows/release.yml
vendored
|
@ -1,14 +0,0 @@
|
|||
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,7 +44,3 @@ app.*.map.json
|
|||
ios
|
||||
.metadata
|
||||
pubspec.lock
|
||||
|
||||
# FVM Version Cache
|
||||
.fvm/
|
||||
.fvmrc
|
||||
|
|
17
CHANGELOG.md
17
CHANGELOG.md
|
@ -1,20 +1,3 @@
|
|||
## 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.
|
||||
|
|
105
README.md
105
README.md
|
@ -6,62 +6,57 @@ 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:
|
||||
|
||||
```yaml
|
||||
```
|
||||
flutter_start:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_start
|
||||
ref: 4.1.0
|
||||
ref: <Version>
|
||||
```
|
||||
|
||||
## go_router
|
||||
|
||||
Add `go_router` as dependency to your project.
|
||||
To use the module within your Flutter-application with predefined `Go_router` routes you should add the following:
|
||||
|
||||
Add go_router as dependency to your project.
|
||||
Add the following configuration to your flutter_application:
|
||||
|
||||
```
|
||||
List<GoRoute> getStartStoryRoutes() => getStartStoryRoutes();
|
||||
StartUserStoryConfiguration startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||
```
|
||||
|
||||
Or with options:
|
||||
and set the values as you wish.
|
||||
|
||||
Place the following code somewhere in your project where it can be accessed globally:
|
||||
Next add the `StartUserStoryConfiguration` to `getStartStoryRoutes` Like so:
|
||||
|
||||
```
|
||||
var startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||
```
|
||||
|
||||
```
|
||||
List<GoRoute> getStartStoryRoutes() => getStartStoryRoutes(
|
||||
configuration: startUserStoryConfiguration,
|
||||
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
|
||||
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(
|
||||
routes: <RouteBase>[
|
||||
...getStartStoryRoutes()
|
||||
...getStartRoutes()
|
||||
],
|
||||
);
|
||||
```
|
||||
|
||||
The routes that can be used to navigate are:
|
||||
|
||||
For routing to the `splashScreen`:
|
||||
For routing to the `SplashScreen`:
|
||||
|
||||
```
|
||||
static const String splashScreen = '/splashScreen';
|
||||
```
|
||||
|
||||
For routing to the `introduction`:
|
||||
For routing to the `Introduction`:
|
||||
|
||||
```
|
||||
static const String introduction = '/introduction';
|
||||
```
|
||||
|
||||
For routing to the `home`:
|
||||
For routing to the `HomeEntry`:
|
||||
|
||||
```
|
||||
static const String home = '/home';
|
||||
|
@ -78,64 +73,42 @@ final GoRouter _router = GoRouter(
|
|||
);
|
||||
```
|
||||
|
||||
## Navigator
|
||||
To use the module within your Flutter-application without predefined `Go_router` routes but with `Navigator` routes add the following :
|
||||
|
||||
Add the following code to the build-method of a chosen widget like so:
|
||||
```
|
||||
class Example extends StatelessWidget {
|
||||
const Example({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return NavigatorStartUserStory(
|
||||
onComplete: (context) {},
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
or with options:
|
||||
|
||||
Place the following code somewhere in your project where it can be accessed globally:
|
||||
Add the following configuration to your flutter_application:
|
||||
|
||||
```
|
||||
var startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||
StartUserStoryConfiguration startUserStoryConfiguration = const StartUserStoryConfiguration();
|
||||
```
|
||||
|
||||
```
|
||||
class Example extends StatelessWidget {
|
||||
const Example({super.key});
|
||||
Add the following code to the build-method of a chosen widget:
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return NavigatorStartUserStory(
|
||||
configuration: startUserStoryConfiguration,
|
||||
onComplete: (context) {},
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
startNavigatorUserStory(startUserStoryConfiguration, context);
|
||||
```
|
||||
|
||||
If the splashScreenBuilder is not used the SplashScreen will be skipped.
|
||||
|
||||
The `StartUserStoryConfiguration` has its own parameters, as specified below:
|
||||
| Parameter | Explanation |
|
||||
|-----------|-------------|
|
||||
| `splashScreenBuilder` | The builder to override the default splashScreen |
|
||||
| `introductionBuilder` | A builder to wrap the introductions in your own page |
|
||||
| `introductionOptionsBuilder` | The builder to override the default `introductionOptions` |
|
||||
|`introductionService` | The service to override the default `introductionService` |
|
||||
| `homeScreenRoute` | The route to navigate to after the introduction or splashScreen is completed |
|
||||
| `introductionFallbackScreen` | The screen that is shown when something goes wrong fetching data for the introduction |
|
||||
| `introductionScrollPhysics` | The scroll physics for the introduction |
|
||||
| `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 |
|
||||
|
||||
| splashScreenBuilder | The builder for the splashScreen. |
|
||||
| introductionBuilder | The builder for the introduction. |
|
||||
| introductionOptionsBuilder | The options for the introduction. |
|
||||
| introductionService | The service for the introduction. Default IntroductionService (SharedPreferencesIntroductionDataProvider()) |
|
||||
| homeEntry | The widget that will be shown after the introduction. |
|
||||
| homeScreenRoute | The route that will be shown after the introduction when using gorouter |
|
||||
| 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|
|
||||
| minimumSplashScreenDuration | The minimum duration the splashScreen should be shown. |
|
||||
| splashScreenFuture | The future that will be awaited before the splashScreen is closed. |
|
||||
| splashScreenCenterWidget | The widget that will be shown in the center of the splashScreen. |
|
||||
| splashScreenBackgroundColor | The background color of the splashScreen. |
|
||||
| canPopFromIntroduction | Whether or not the introduction can be popped. |
|
||||
| killswitchService | The service for the killswitch. Instead of the default service |
|
||||
| showSplashScreen | Whether or not the splashScreen should be shown. |
|
||||
|
||||
## Issues
|
||||
|
||||
|
|
3
example/.gitignore
vendored
3
example/.gitignore
vendored
|
@ -31,9 +31,6 @@ migrate_working_dir/
|
|||
.pub/
|
||||
/build/
|
||||
|
||||
# platforms
|
||||
/web
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
# 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.
|
|
@ -39,6 +39,38 @@ StartUserStoryConfiguration config = StartUserStoryConfiguration(
|
|||
splashScreenBuilder: (context, onFinish) => SplashScreen(
|
||||
onFinish: onFinish,
|
||||
),
|
||||
introductionOptionsBuilder: (ctx) => IntroductionOptions(
|
||||
pages: [
|
||||
const IntroductionPage(
|
||||
title: Text('First page'),
|
||||
text: Text('Wow a page'),
|
||||
graphic: FlutterLogo(),
|
||||
),
|
||||
const IntroductionPage(
|
||||
title: Text('Second page'),
|
||||
text: Text('Another page'),
|
||||
graphic: FlutterLogo(),
|
||||
),
|
||||
const IntroductionPage(
|
||||
title: Text('Third page'),
|
||||
text: Text('The final page of this app'),
|
||||
graphic: 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 {
|
||||
|
@ -82,3 +114,17 @@ class HomeEntry extends StatelessWidget {
|
|||
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,8 +12,10 @@ dependencies:
|
|||
flutter_start:
|
||||
path: ../
|
||||
flutter_introduction_shared_preferences:
|
||||
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
|
||||
version: ^5.0.0
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_introduction
|
||||
ref: 3.0.0
|
||||
path: packages/flutter_introduction_shared_preferences
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -24,6 +24,7 @@ List<GoRoute> getStartStoryRoutes({
|
|||
pageBuilder: (context, state) {
|
||||
var go = context.go;
|
||||
var isAllowedToPassThrough = false;
|
||||
var introductionSeen = false;
|
||||
String? routeAfterSplash;
|
||||
Future<void> splashLoadingMethod() async {
|
||||
await Future.wait<void>(
|
||||
|
@ -39,6 +40,11 @@ List<GoRoute> getStartStoryRoutes({
|
|||
await killswitchService.isKillswitchActive();
|
||||
}
|
||||
|
||||
var introService = configuration.introductionService ??
|
||||
IntroductionService(
|
||||
SharedPreferencesIntroductionDataProvider(),
|
||||
);
|
||||
introductionSeen = !await introService.shouldShow();
|
||||
if (context.mounted)
|
||||
routeAfterSplash = await configuration.splashScreenFuture
|
||||
?.call(context) ??
|
||||
|
@ -56,7 +62,7 @@ List<GoRoute> getStartStoryRoutes({
|
|||
|
||||
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
||||
|
||||
if ((!configuration.showIntroduction) && context.mounted) {
|
||||
if (!configuration.showIntroduction || introductionSeen) {
|
||||
return go(
|
||||
routeAfterSplash ?? StartUserStoryRoutes.home,
|
||||
);
|
||||
|
@ -79,7 +85,7 @@ List<GoRoute> getStartStoryRoutes({
|
|||
body: Center(
|
||||
child:
|
||||
configuration.splashScreenCenterWidget?.call(context) ??
|
||||
defaultSplashScreen(context),
|
||||
defaultSplashScreen,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -19,11 +19,13 @@ class NavigatorStartUserStory extends StatelessWidget {
|
|||
final void Function(BuildContext context) onComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Navigator(
|
||||
onGenerateInitialRoutes: (_, __) => [
|
||||
_getInitialRoute(configuration, onComplete),
|
||||
],
|
||||
);
|
||||
Widget build(BuildContext context) {
|
||||
if (!configuration.showSplashScreen) {
|
||||
return _introduction(configuration, context, onComplete);
|
||||
}
|
||||
|
||||
return _splashScreen(configuration, context, onComplete);
|
||||
}
|
||||
}
|
||||
|
||||
/// Enter the start user story with the Navigator 1.0 API.
|
||||
|
@ -40,15 +42,6 @@ Future<void> startNavigatorUserStory(
|
|||
StartUserStoryConfiguration configuration, {
|
||||
required void Function(BuildContext context) onComplete,
|
||||
}) 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(
|
||||
builder: (context) => _splashScreen(
|
||||
configuration,
|
||||
|
@ -66,7 +59,8 @@ MaterialPageRoute<dynamic> _getInitialRoute(
|
|||
),
|
||||
);
|
||||
}
|
||||
return initialRoute;
|
||||
|
||||
await Navigator.of(context).push(initialRoute);
|
||||
}
|
||||
|
||||
Widget _splashScreen(
|
||||
|
@ -77,6 +71,7 @@ Widget _splashScreen(
|
|||
var navigator = Navigator.of(context);
|
||||
|
||||
var isAllowedToPassThrough = false;
|
||||
var introductionSeen = false;
|
||||
|
||||
Future<void> splashHandler() async {
|
||||
await Future.wait<void>(
|
||||
|
@ -92,6 +87,12 @@ Widget _splashScreen(
|
|||
isAllowedToPassThrough =
|
||||
await killswitchService.isKillswitchActive();
|
||||
}
|
||||
|
||||
var introService = configuration.introductionService ??
|
||||
IntroductionService(
|
||||
SharedPreferencesIntroductionDataProvider(),
|
||||
);
|
||||
introductionSeen = !await introService.shouldShow();
|
||||
},
|
||||
),
|
||||
Future.delayed(
|
||||
|
@ -104,16 +105,13 @@ Widget _splashScreen(
|
|||
|
||||
if (configuration.useKillswitch && isAllowedToPassThrough) return;
|
||||
|
||||
var introService = configuration.introductionService ??
|
||||
IntroductionService(SharedPreferencesIntroductionDataProvider());
|
||||
|
||||
var shouldShowIntroduction =
|
||||
configuration.showIntroduction && await introService.shouldShow();
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
if (!shouldShowIntroduction) return onComplete(context);
|
||||
if ((!configuration.showIntroduction || introductionSeen) &&
|
||||
context.mounted) {
|
||||
onComplete(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
await navigator.pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _introduction(
|
||||
|
@ -124,17 +122,17 @@ Widget _splashScreen(
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
unawaited(splashHandler());
|
||||
}
|
||||
|
||||
var builder = configuration.splashScreenBuilder;
|
||||
|
||||
if (builder == null) {
|
||||
unawaited(splashHandler());
|
||||
return Scaffold(
|
||||
backgroundColor: configuration.splashScreenBackgroundColor,
|
||||
body: Center(
|
||||
child: configuration.splashScreenCenterWidget?.call(context) ??
|
||||
defaultSplashScreen(context),
|
||||
defaultSplashScreen,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
Text defaultSplashScreen(BuildContext context) => Text(
|
||||
'iconinstagram',
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
const defaultSplashScreen = Text(
|
||||
'Splash Screen',
|
||||
style: TextStyle(
|
||||
color: Color(0xff71C6D1),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 32,
|
||||
),
|
||||
);
|
||||
|
|
25
pubspec.yaml
25
pubspec.yaml
|
@ -1,8 +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."
|
||||
version: 4.2.4
|
||||
|
||||
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
|
||||
publish_to: "none"
|
||||
version: 4.0.0
|
||||
|
||||
environment:
|
||||
sdk: ">=3.2.5 <4.0.0"
|
||||
|
@ -10,16 +9,20 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
cupertino_icons: ">=1.0.2 <2.0.0"
|
||||
go_router: ">=14.2.0 <15.0.0"
|
||||
http: ">=1.2.1 <2.0.0"
|
||||
package_info_plus: ">=8.0.0 <9.0.0"
|
||||
cupertino_icons: ^1.0.2
|
||||
go_router: any
|
||||
http: any
|
||||
package_info_plus: any
|
||||
flutter_introduction:
|
||||
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub
|
||||
version: ^5.0.0
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_introduction
|
||||
ref: 3.0.0
|
||||
path: packages/flutter_introduction
|
||||
flutter_introduction_shared_preferences:
|
||||
hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/
|
||||
version: ^5.0.0
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_introduction
|
||||
ref: 3.0.0
|
||||
path: packages/flutter_introduction_shared_preferences
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
// 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