mirror of
https://github.com/Iconica-Development/flutter_start.git
synced 2025-05-18 18:13:45 +02:00
feat!: add NavigatorStartUserStory widget
This also changes the startNavigatorUserStory function return type from a widget to Future<void>, as that starts the story. The widget immediately displays the initial screen. This is a breaking change.
This commit is contained in:
parent
da2a50c9a7
commit
2cf2b1c961
3 changed files with 51 additions and 10 deletions
|
@ -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()),
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue