From 84e629d5b22e3e475b5ec6bda32305d620f24b1a Mon Sep 17 00:00:00 2001 From: mike doornenbal Date: Wed, 5 Jun 2024 10:35:03 +0200 Subject: [PATCH] fix: feedback on userstory --- CHANGELOG.md | 5 + README.md | 109 +++++++++++------- example/lib/main.dart | 46 -------- example/pubspec.yaml | 2 +- .../flutter_start_userstory_go_router.dart | 10 +- .../flutter_start_userstory_navigator.dart | 12 +- lib/src/widgets/default_splash_screen.dart | 12 +- pubspec.yaml | 6 +- 8 files changed, 85 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faeca5f..db31372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 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. diff --git a/README.md b/README.md index 8b83abd..6c7deba 100644 --- a/README.md +++ b/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: -``` +```yaml flutter_start: git: url: https://github.com/Iconica-Development/flutter_start - ref: + 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: ``` -StartUserStoryConfiguration startUserStoryConfiguration = const StartUserStoryConfiguration(); +List 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 getStartRoutes() => getStartStoryRoutes( - startUserStoryConfiguration, +var startUserStoryConfiguration = const StartUserStoryConfiguration(); +``` + +``` +List 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( routes: [ - ...getStartRoutes() + ...getStartStoryRoutes() ], ); ``` 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`: @@ -73,42 +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 : - -Add the following configuration to your flutter_application: +## Navigator +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: | Parameter | Explanation | |-----------|-------------| -| 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. | +| `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 | + ## Issues diff --git a/example/lib/main.dart b/example/lib/main.dart index 97ac654..443e605 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,38 +39,6 @@ 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 { @@ -114,17 +82,3 @@ class HomeEntry extends StatelessWidget { body: const Center(child: Text('HomeEntry')), ); } - -class ExampleIntroductionDataProvider - implements SharedPreferencesIntroductionDataProvider { - @override - String key = 'example'; - - @override - Future setCompleted({bool value = true}) async => - // ignore: void_checks - false; - - @override - Future shouldShow() async => true; -} diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 24e9014..8fd701e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: flutter_introduction_shared_preferences: git: url: https://github.com/Iconica-Development/flutter_introduction - ref: 3.0.0 + ref: 3.1.0 path: packages/flutter_introduction_shared_preferences dev_dependencies: diff --git a/lib/src/user_stories/flutter_start_userstory_go_router.dart b/lib/src/user_stories/flutter_start_userstory_go_router.dart index ae3fbfb..57df7e0 100644 --- a/lib/src/user_stories/flutter_start_userstory_go_router.dart +++ b/lib/src/user_stories/flutter_start_userstory_go_router.dart @@ -24,7 +24,6 @@ List getStartStoryRoutes({ pageBuilder: (context, state) { var go = context.go; var isAllowedToPassThrough = false; - var introductionSeen = false; String? routeAfterSplash; Future splashLoadingMethod() async { await Future.wait( @@ -40,11 +39,6 @@ List getStartStoryRoutes({ await killswitchService.isKillswitchActive(); } - var introService = configuration.introductionService ?? - IntroductionService( - SharedPreferencesIntroductionDataProvider(), - ); - introductionSeen = !await introService.shouldShow(); if (context.mounted) routeAfterSplash = await configuration.splashScreenFuture ?.call(context) ?? @@ -62,7 +56,7 @@ List getStartStoryRoutes({ if (configuration.useKillswitch && isAllowedToPassThrough) return; - if (!configuration.showIntroduction || introductionSeen) { + if ((!configuration.showIntroduction) && context.mounted) { return go( routeAfterSplash ?? StartUserStoryRoutes.home, ); @@ -85,7 +79,7 @@ List getStartStoryRoutes({ body: Center( child: configuration.splashScreenCenterWidget?.call(context) ?? - defaultSplashScreen, + defaultSplashScreen(context), ), ), ); diff --git a/lib/src/user_stories/flutter_start_userstory_navigator.dart b/lib/src/user_stories/flutter_start_userstory_navigator.dart index 5fc09fd..3774db2 100644 --- a/lib/src/user_stories/flutter_start_userstory_navigator.dart +++ b/lib/src/user_stories/flutter_start_userstory_navigator.dart @@ -71,7 +71,6 @@ Widget _splashScreen( var navigator = Navigator.of(context); var isAllowedToPassThrough = false; - var introductionSeen = false; Future splashHandler() async { await Future.wait( @@ -87,12 +86,6 @@ Widget _splashScreen( isAllowedToPassThrough = await killswitchService.isKillswitchActive(); } - - var introService = configuration.introductionService ?? - IntroductionService( - SharedPreferencesIntroductionDataProvider(), - ); - introductionSeen = !await introService.shouldShow(); }, ), Future.delayed( @@ -105,8 +98,7 @@ Widget _splashScreen( if (configuration.useKillswitch && isAllowedToPassThrough) return; - if ((!configuration.showIntroduction || introductionSeen) && - context.mounted) { + if ((!configuration.showIntroduction) && context.mounted) { onComplete(context); return; } @@ -132,7 +124,7 @@ Widget _splashScreen( backgroundColor: configuration.splashScreenBackgroundColor, body: Center( child: configuration.splashScreenCenterWidget?.call(context) ?? - defaultSplashScreen, + defaultSplashScreen(context), ), ); } diff --git a/lib/src/widgets/default_splash_screen.dart b/lib/src/widgets/default_splash_screen.dart index 63e1ed6..23d795d 100644 --- a/lib/src/widgets/default_splash_screen.dart +++ b/lib/src/widgets/default_splash_screen.dart @@ -1,10 +1,6 @@ import 'package:flutter/material.dart'; -const defaultSplashScreen = Text( - 'Splash Screen', - style: TextStyle( - color: Color(0xff71C6D1), - fontWeight: FontWeight.w800, - fontSize: 32, - ), -); +Text defaultSplashScreen(BuildContext context) => Text( + 'iconinstagram', + style: Theme.of(context).textTheme.titleLarge, + ); diff --git a/pubspec.yaml b/pubspec.yaml index 8782ac8..d1814a4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: 4.0.0 +version: 4.1.0 environment: sdk: ">=3.2.5 <4.0.0" @@ -16,12 +16,12 @@ dependencies: flutter_introduction: git: url: https://github.com/Iconica-Development/flutter_introduction - ref: 3.0.0 + ref: 3.1.0 path: packages/flutter_introduction flutter_introduction_shared_preferences: git: url: https://github.com/Iconica-Development/flutter_introduction - ref: 3.0.0 + ref: 3.1.0 path: packages/flutter_introduction_shared_preferences dev_dependencies: