Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate after seconds function #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/splashscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class SplashScreen extends StatefulWidget {
/// String or Widget
final Object? navigateAfterSeconds;

/// If you are using some route's management and needs to use a function to navigate
/// to another page
final void Function()? navigateAfterSecondsFunction;

/// Main image size
final double? photoSize;

Expand Down Expand Up @@ -85,6 +89,7 @@ class SplashScreen extends StatefulWidget {
this.gradientBackground,
required this.useLoader,
this.routeName,
this.navigateAfterSecondsFunction,
}) : assert(
routeName == null ||
(routeName is String && routeName.startsWith('/')),
Expand Down Expand Up @@ -124,6 +129,7 @@ class SplashScreen extends StatefulWidget {
Route? pageRoute,
GestureTapCallback? onClick,
Object? navigateAfterSeconds,
void Function()? navigateAfterSecondsFunction,
Text title = const Text(''),
TextStyle styleTextUnderTheLoader = _defaultStyleTextUnderTheLoader,
ImageProvider? imageBackground,
Expand All @@ -142,6 +148,7 @@ class SplashScreen extends StatefulWidget {
pageRoute: pageRoute,
onClick: onClick,
navigateAfterSeconds: navigateAfterSeconds,
navigateAfterSecondsFunction: navigateAfterSecondsFunction,
title: title,
styleTextUnderTheLoader: styleTextUnderTheLoader,
imageBackground: imageBackground,
Expand All @@ -161,6 +168,7 @@ class SplashScreen extends StatefulWidget {
Route? pageRoute,
GestureTapCallback? onClick,
dynamic navigateAfterSeconds,
void Function()? navigateAfterSecondsFunction,
Text title = const Text(''),
TextStyle styleTextUnderTheLoader = _defaultStyleTextUnderTheLoader,
ImageProvider? imageBackground,
Expand All @@ -179,6 +187,7 @@ class SplashScreen extends StatefulWidget {
pageRoute: pageRoute,
onClick: onClick,
navigateAfterSeconds: navigateAfterSeconds,
navigateAfterSecondsFunction: navigateAfterSecondsFunction,
title: title,
styleTextUnderTheLoader: styleTextUnderTheLoader,
imageBackground: imageBackground,
Expand All @@ -197,7 +206,9 @@ class _SplashScreenState extends State<SplashScreen> {
super.initState();
if (widget.navigateAfterFuture == null) {
Timer(Duration(seconds: widget.seconds!), () {
if (widget.navigateAfterSeconds is String) {
if (widget.navigateAfterSecondsFunction != null)
widget.navigateAfterSecondsFunction!();
else if (widget.navigateAfterSeconds is String) {
// It's fairly safe to assume this is using the in-built material
// named route component
Navigator.of(context).pushReplacementNamed(
Expand Down