Merge pull request #26 from Iconica-Development/feature/default_configuration

feat: add default configuration
This commit is contained in:
Gorter-dev 2024-04-18 09:33:49 +02:00 committed by GitHub
commit fc65e98f96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 193 additions and 18 deletions

View file

@ -1,3 +1,8 @@
## 4.0.0
- Added default introduction page.
- Added default splash screen.
- Changed the way the splash screen is enabled/disabled.
## 3.0.0 ## 3.0.0
BREAKING: BREAKING:

View file

@ -93,13 +93,22 @@ The `StartUserStoryConfiguration` has its own parameters, as specified below:
| Parameter | Explanation | | Parameter | Explanation |
|-----------|-------------| |-----------|-------------|
| splashScreenBuilder | The builder for the splashScreen. | | splashScreenBuilder | The builder for the splashScreen. |
| introductionOptions | The options for the introduction. | | introductionBuilder | The builder for the introduction. |
| introductionOptionsBuilder | The options for the introduction. |
| introductionService | The service for the introduction. Default IntroductionService (SharedPreferencesIntroductionDataProvider()) | | introductionService | The service for the introduction. Default IntroductionService (SharedPreferencesIntroductionDataProvider()) |
| homeEntry | The widget that will be shown after the introduction. | | 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. | | introductionFallbackScreen | The widget that will be shown when the introduction is skipped. |
| introductionScrollPhysics | The scrollPhysics for the introduction. | | introductionScrollPhysics | The scrollPhysics for the introduction. |
| showIntroduction | Whether or not the introduction should be shown. | | 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| | 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. |
## Issues ## Issues

View file

@ -20,9 +20,10 @@ class StartUserStoryConfiguration {
this.minimumSplashScreenDuration = 3, this.minimumSplashScreenDuration = 3,
this.splashScreenFuture, this.splashScreenFuture,
this.splashScreenCenterWidget, this.splashScreenCenterWidget,
this.splashScreenBackgroundColor, this.splashScreenBackgroundColor = const Color(0xff212121),
this.canPopFromIntroduction = true, this.canPopFromIntroduction = true,
this.killswitchService, this.killswitchService,
this.showSplashScreen = true,
}); });
/// You can use this to build your own splash screen. /// You can use this to build your own splash screen.
@ -68,9 +69,6 @@ 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 /// If the splash screen should be shown or not.
bool get startWithIntroScreen => final bool showSplashScreen;
splashScreenBuilder == null &&
splashScreenCenterWidget == null &&
splashScreenBackgroundColor == null;
} }

View file

@ -11,7 +11,8 @@ import 'package:flutter_start/src/go_router.dart';
import 'package:flutter_start/src/models/start_configuration.dart'; import 'package:flutter_start/src/models/start_configuration.dart';
import 'package:flutter_start/src/routes.dart'; import 'package:flutter_start/src/routes.dart';
import 'package:flutter_start/src/services/killswitch_service.dart'; import 'package:flutter_start/src/services/killswitch_service.dart';
import 'package:flutter_start/src/widgets/default_introduction_options.dart';
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
List<GoRoute> getStartStoryRoutes( List<GoRoute> getStartStoryRoutes(
@ -84,7 +85,7 @@ List<GoRoute> getStartStoryRoutes(
body: Center( body: Center(
child: child:
configuration.splashScreenCenterWidget?.call(context) ?? configuration.splashScreenCenterWidget?.call(context) ??
const SizedBox.shrink(), defaultSplashScreen,
), ),
), ),
); );
@ -104,7 +105,7 @@ List<GoRoute> getStartStoryRoutes(
); );
}, },
options: configuration.introductionOptionsBuilder?.call(context) ?? options: configuration.introductionOptionsBuilder?.call(context) ??
const IntroductionOptions(), defaultIntroductionOptions,
physics: configuration.introductionScrollPhysics, physics: configuration.introductionScrollPhysics,
child: configuration.introductionFallbackScreen, child: configuration.introductionFallbackScreen,
); );

View file

@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart'; 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';
import 'package:flutter_start/src/widgets/default_introduction_options.dart';
import 'package:flutter_start/src/widgets/default_splash_screen.dart';
/// Initial screen of the user story. /// Initial screen of the user story.
/// ///
@ -19,7 +21,7 @@ class NavigatorStartUserStory extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (configuration.startWithIntroScreen) { if (!configuration.showSplashScreen) {
return _introduction(configuration, context, onComplete); return _introduction(configuration, context, onComplete);
} }
@ -49,7 +51,7 @@ Future<void> startNavigatorUserStory(
), ),
); );
if (configuration.startWithIntroScreen) { if (!configuration.showSplashScreen && configuration.showIntroduction) {
initialRoute = MaterialPageRoute( initialRoute = MaterialPageRoute(
builder: (context) => _introduction( builder: (context) => _introduction(
configuration, configuration,
@ -131,7 +133,7 @@ Widget _splashScreen(
backgroundColor: configuration.splashScreenBackgroundColor, backgroundColor: configuration.splashScreenBackgroundColor,
body: Center( body: Center(
child: configuration.splashScreenCenterWidget?.call(context) ?? child: configuration.splashScreenCenterWidget?.call(context) ??
const SizedBox.shrink(), defaultSplashScreen,
), ),
); );
} }
@ -152,14 +154,18 @@ Widget _introduction(
IntroductionService(SharedPreferencesIntroductionDataProvider()), IntroductionService(SharedPreferencesIntroductionDataProvider()),
navigateTo: () async => onComplete(context), navigateTo: () async => onComplete(context),
options: configuration.introductionOptionsBuilder?.call(context) ?? options: configuration.introductionOptionsBuilder?.call(context) ??
const IntroductionOptions(), defaultIntroductionOptions,
physics: configuration.introductionScrollPhysics, physics: configuration.introductionScrollPhysics,
child: configuration.introductionFallbackScreen, child: configuration.introductionFallbackScreen,
); );
return PopScope( return PopScope(
canPop: configuration.canPopFromIntroduction, canPop: configuration.canPopFromIntroduction,
child: Scaffold( child: configuration.introductionBuilder?.call(
body: introduction, context,
), introduction,
) ??
Scaffold(
body: introduction,
),
); );
} }

View file

@ -0,0 +1,146 @@
import 'package:flutter/material.dart';
import 'package:flutter_start/flutter_start.dart';
IntroductionOptions defaultIntroductionOptions = IntroductionOptions(
introductionTranslations: const IntroductionTranslations(
finishButton: 'Get Started',
nextButton: 'Next',
previousButton: 'Previous',
),
buttonMode: IntroductionScreenButtonMode.text,
indicatorMode: IndicatorMode.dot,
buttonBuilder: (p0, p1, p2, p3) => defaultIntroductionButton(p0, p1, p2),
introductionButtonTextstyles: defaultIntroductionButtonTextstyles,
pages: defaultIntroductionPages,
);
const titleStyle = TextStyle(
color: Color(0xff71C6D1),
fontSize: 24,
fontWeight: FontWeight.w700,
);
final defaultIntroductionPages = [
IntroductionPage(
decoration: const BoxDecoration(
color: Color(0xffFAF9F6),
),
title: const Column(
children: [
SizedBox(height: 100),
Text('welcome to iconinstagram', style: titleStyle),
SizedBox(height: 6),
Text(
'Welcome to the world of Instagram, where creativity'
' knows no bounds and connections are made'
' through captivating visuals.',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
],
),
text: const Text(''),
),
IntroductionPage(
decoration: const BoxDecoration(
color: Color(0xffFAF9F6),
),
title: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(height: 100),
Text(
'discover iconinstagram',
style: titleStyle,
),
SizedBox(height: 6),
Text(
'Dive into the vibrant world of'
' Instagram and discover endless possibilities.'
' From stunning photography to engaging videos,'
' Instagram offers a diverse range of content to explore and enjoy.',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
],
),
text: const Text(''),
),
IntroductionPage(
decoration: const BoxDecoration(
color: Color(0xffFAF9F6),
),
title: const Column(
children: [
SizedBox(height: 100),
Text(
'elevate your experience',
style: titleStyle,
),
SizedBox(height: 6),
Text(
'Whether promoting your business, or connecting'
' with friends and family, Instagram provides the'
' tools and platform to make your voice heard.',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
],
),
text: const Text(''),
),
];
const defaultIntroductionButtonTextstyles = IntroductionButtonTextstyles(
finishButtonStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
nextButtonStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
previousButtonStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
skipButtonStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
);
Widget defaultIntroductionButton(
BuildContext context,
void Function() onTap,
Widget buttonWidget,
) =>
InkWell(
onTap: onTap,
child: Container(
width: 180,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(
0xff979797,
),
),
),
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: buttonWidget,
),
),
),
);

View file

@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
const defaultSplashScreen = Text(
'Splash Screen',
style: TextStyle(
color: Color(0xff71C6D1),
fontWeight: FontWeight.w800,
fontSize: 32,
),
);

View file

@ -1,7 +1,7 @@
name: flutter_start name: flutter_start
description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home." description: "Flutter_start is a package that allows you to jumpstart your application with a splashScreen, introduction and a home."
publish_to: "none" publish_to: "none"
version: 3.0.0 version: 4.0.0
environment: environment:
sdk: ">=3.2.5 <4.0.0" sdk: ">=3.2.5 <4.0.0"