Merge pull request #23 from Iconica-Development/16-run-the-start-user-story-without-go-router-from-the-start-of-the-app

feat!: add NavigatorStartUserStory widget
This commit is contained in:
Gorter-dev 2024-04-04 16:11:33 +02:00 committed by GitHub
commit 06dc5b8b7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 10 deletions

View file

@ -20,9 +20,8 @@ class Home extends StatelessWidget {
const Home({super.key}); const Home({super.key});
@override @override
Widget build(BuildContext context) => startNavigatorUserStory( Widget build(BuildContext context) => NavigatorStartUserStory(
context, configuration: config,
config,
onComplete: (context) async { onComplete: (context) async {
await Navigator.of(context).pushReplacement( await Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const HomeEntry()), MaterialPageRoute(builder: (context) => const HomeEntry()),

View file

@ -67,4 +67,10 @@ 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
bool get startWithIntroScreen =>
splashScreenBuilder == null &&
splashScreenCenterWidget == null &&
splashScreenBackgroundColor == null;
} }

View file

@ -4,6 +4,29 @@ 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';
/// Initial screen of the user story.
///
/// Use this when defining an initial route.
class NavigatorStartUserStory extends StatelessWidget {
const NavigatorStartUserStory({
required this.onComplete,
this.configuration = const StartUserStoryConfiguration(),
super.key,
});
final StartUserStoryConfiguration configuration;
final void Function(BuildContext context) onComplete;
@override
Widget build(BuildContext context) {
if (configuration.showIntroduction) {
return _introduction(configuration, context, 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.
/// ///
/// Requires a Navigator widget to exist in the given [context]. /// Requires a Navigator widget to exist in the given [context].
@ -13,17 +36,30 @@ import 'package:flutter_start/src/services/killswitch_service.dart';
/// [onComplete] triggers as soon as the userstory is finished. /// [onComplete] triggers as soon as the userstory is finished.
/// ///
/// The context provided here is a context has a guaranteed navigator. /// The context provided here is a context has a guaranteed navigator.
Widget startNavigatorUserStory( Future<void> startNavigatorUserStory(
BuildContext context, BuildContext context,
StartUserStoryConfiguration configuration, { StartUserStoryConfiguration configuration, {
required void Function(BuildContext context) onComplete, required void Function(BuildContext context) onComplete,
}) { }) async {
if (configuration.splashScreenBuilder == null && var initialRoute = MaterialPageRoute(
configuration.splashScreenCenterWidget == null && builder: (context) => _splashScreen(
configuration.splashScreenBackgroundColor == null) { configuration,
return _introduction(configuration, context, onComplete); context,
onComplete,
),
);
if (configuration.startWithIntroScreen) {
initialRoute = MaterialPageRoute(
builder: (context) => _introduction(
configuration,
context,
onComplete,
),
);
} }
return _splashScreen(configuration, context, onComplete);
await Navigator.of(context).push(initialRoute);
} }
Widget _splashScreen( Widget _splashScreen(