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});
@override
Widget build(BuildContext context) => startNavigatorUserStory(
context,
config,
Widget build(BuildContext context) => NavigatorStartUserStory(
configuration: config,
onComplete: (context) async {
await Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const HomeEntry()),

View file

@ -67,4 +67,10 @@ class StartUserStoryConfiguration {
/// Allow popping from introduction, defaults to true
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/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.
///
/// 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.
///
/// The context provided here is a context has a guaranteed navigator.
Widget startNavigatorUserStory(
Future<void> startNavigatorUserStory(
BuildContext context,
StartUserStoryConfiguration configuration, {
required void Function(BuildContext context) onComplete,
}) {
if (configuration.splashScreenBuilder == null &&
configuration.splashScreenCenterWidget == null &&
configuration.splashScreenBackgroundColor == null) {
return _introduction(configuration, context, onComplete);
}) async {
var initialRoute = MaterialPageRoute(
builder: (context) => _splashScreen(
configuration,
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(