mirror of
https://github.com/Iconica-Development/flutter_start.git
synced 2025-05-18 18:13:45 +02:00
Merge pull request #21 from Iconica-Development/18-change-the-home-entry-from-a-widget-to-a-callback
feat!: change homeEntry to an onComplete callback
This commit is contained in:
commit
da2a50c9a7
3 changed files with 32 additions and 31 deletions
|
@ -20,8 +20,15 @@ class Home extends StatelessWidget {
|
|||
const Home({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
startNavigatorUserStory(config, context);
|
||||
Widget build(BuildContext context) => startNavigatorUserStory(
|
||||
context,
|
||||
config,
|
||||
onComplete: (context) async {
|
||||
await Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (context) => const HomeEntry()),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<GoRoute> getStartRoutes() => getStartStoryRoutes(
|
||||
|
@ -33,7 +40,6 @@ StartUserStoryConfiguration config = StartUserStoryConfiguration(
|
|||
splashScreenBuilder: (context, onFinish) => SplashScreen(
|
||||
onFinish: onFinish,
|
||||
),
|
||||
homeEntry: const HomeEntry(),
|
||||
introductionOptionsBuilder: (ctx) => IntroductionOptions(
|
||||
pages: [
|
||||
IntroductionPage(
|
||||
|
|
|
@ -12,7 +12,6 @@ class StartUserStoryConfiguration {
|
|||
this.introductionBuilder,
|
||||
this.introductionOptionsBuilder,
|
||||
this.introductionService,
|
||||
this.homeEntry,
|
||||
this.homeScreenRoute,
|
||||
this.introductionFallbackScreen,
|
||||
this.introductionScrollPhysics,
|
||||
|
@ -41,8 +40,6 @@ class StartUserStoryConfiguration {
|
|||
/// The route that is used to navigate to the home screen.
|
||||
final String? homeScreenRoute;
|
||||
|
||||
final Widget? homeEntry;
|
||||
|
||||
final IntroductionOptions Function(BuildContext context)?
|
||||
introductionOptionsBuilder;
|
||||
final Widget? introductionFallbackScreen;
|
||||
|
|
|
@ -4,21 +4,32 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_start/flutter_start.dart';
|
||||
import 'package:flutter_start/src/services/killswitch_service.dart';
|
||||
|
||||
/// Enter the start user story with the Navigator 1.0 API.
|
||||
///
|
||||
/// Requires a Navigator widget to exist in the given [context].
|
||||
///
|
||||
/// Customization can be done through the [configuration] parameter.
|
||||
///
|
||||
/// [onComplete] triggers as soon as the userstory is finished.
|
||||
///
|
||||
/// The context provided here is a context has a guaranteed navigator.
|
||||
Widget startNavigatorUserStory(
|
||||
StartUserStoryConfiguration configuration,
|
||||
BuildContext context,
|
||||
) {
|
||||
StartUserStoryConfiguration configuration, {
|
||||
required void Function(BuildContext context) onComplete,
|
||||
}) {
|
||||
if (configuration.splashScreenBuilder == null &&
|
||||
configuration.splashScreenCenterWidget == null &&
|
||||
configuration.splashScreenBackgroundColor == null) {
|
||||
return _introduction(configuration, context);
|
||||
return _introduction(configuration, context, onComplete);
|
||||
}
|
||||
return _splashScreen(configuration, context);
|
||||
return _splashScreen(configuration, context, onComplete);
|
||||
}
|
||||
|
||||
Widget _splashScreen(
|
||||
StartUserStoryConfiguration configuration,
|
||||
BuildContext context,
|
||||
void Function(BuildContext context) onComplete,
|
||||
) {
|
||||
var navigator = Navigator.of(context);
|
||||
|
||||
|
@ -59,18 +70,18 @@ Widget _splashScreen(
|
|||
|
||||
if ((!configuration.showIntroduction || introductionSeen) &&
|
||||
context.mounted) {
|
||||
await navigator.pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _home(configuration, context),
|
||||
),
|
||||
);
|
||||
onComplete(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
await navigator.pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _introduction(configuration, context),
|
||||
builder: (context) => _introduction(
|
||||
configuration,
|
||||
context,
|
||||
onComplete,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -98,15 +109,12 @@ Widget _splashScreen(
|
|||
Widget _introduction(
|
||||
StartUserStoryConfiguration configuration,
|
||||
BuildContext context,
|
||||
void Function(BuildContext context) onComplete,
|
||||
) {
|
||||
var introduction = Introduction(
|
||||
service: configuration.introductionService ??
|
||||
IntroductionService(SharedPreferencesIntroductionDataProvider()),
|
||||
navigateTo: () async => Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _home(configuration, context),
|
||||
),
|
||||
),
|
||||
navigateTo: () async => onComplete(context),
|
||||
options: configuration.introductionOptionsBuilder?.call(context) ??
|
||||
const IntroductionOptions(),
|
||||
physics: configuration.introductionScrollPhysics,
|
||||
|
@ -119,13 +127,3 @@ Widget _introduction(
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _home(
|
||||
StartUserStoryConfiguration configuration,
|
||||
BuildContext context,
|
||||
) {
|
||||
var home = configuration.homeEntry;
|
||||
return Scaffold(
|
||||
body: home,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue