From d1ad003c229f84afb3bdfe27552aa4baccb80593 Mon Sep 17 00:00:00 2001 From: Jacques Date: Thu, 1 Feb 2024 14:40:25 +0100 Subject: [PATCH] feat(buttons): Added the possiblity to only have a next button by return zero on the previous button builder --- lib/src/auth_screen.dart | 53 ++++++++++++++---------- lib/src/config/registration_options.dart | 2 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/src/auth_screen.dart b/lib/src/auth_screen.dart index d007268..bc18d18 100644 --- a/lib/src/auth_screen.dart +++ b/lib/src/auth_screen.dart @@ -34,7 +34,7 @@ class AuthScreen extends StatefulWidget { final AppBar? customAppBar; final Color? customBackgroundColor; final Widget Function(Future Function(), String)? nextButtonBuilder; - final Widget Function(VoidCallback, String)? previousButtonBuilder; + final Widget? Function(VoidCallback, String)? previousButtonBuilder; @override State createState() => _AuthScreenState(); @@ -98,6 +98,11 @@ class _AuthScreenState extends State { @override Widget build(BuildContext context) { + var previousButton = widget.previousButtonBuilder?.call( + onPrevious, + widget.previousBtnTitle, + ); + return Scaffold( backgroundColor: widget.customBackgroundColor ?? Colors.white, appBar: _appBar, @@ -145,30 +150,34 @@ class _AuthScreenState extends State { right: 30.0, ), child: Row( - mainAxisAlignment: widget.steps.first != step - ? MainAxisAlignment.spaceBetween - : MainAxisAlignment.end, + mainAxisAlignment: + (widget.previousButtonBuilder != null && + previousButton == null) + ? MainAxisAlignment.spaceAround + : widget.steps.first != step + ? MainAxisAlignment.spaceBetween + : MainAxisAlignment.end, children: [ if (widget.steps.first != step) - widget.previousButtonBuilder?.call( - onPrevious, - widget.previousBtnTitle, - ) ?? - ElevatedButton( - onPressed: onPrevious, - child: Row( - children: [ - const Icon( - Icons.arrow_back, - size: 18, - ), - Padding( - padding: const EdgeInsets.only(left: 4.0), - child: Text(widget.previousBtnTitle), - ), - ], - ), + if (widget.previousButtonBuilder == null) ...[ + ElevatedButton( + onPressed: onPrevious, + child: Row( + children: [ + const Icon( + Icons.arrow_back, + size: 18, + ), + Padding( + padding: const EdgeInsets.only(left: 4.0), + child: Text(widget.previousBtnTitle), + ), + ], ), + ), + ] else if (previousButton != null) ...[ + previousButton + ], widget.nextButtonBuilder?.call( () async { await onNext(step); diff --git a/lib/src/config/registration_options.dart b/lib/src/config/registration_options.dart index 8ed741b..d45c9c6 100644 --- a/lib/src/config/registration_options.dart +++ b/lib/src/config/registration_options.dart @@ -28,7 +28,7 @@ class RegistrationOptions { final AppBar Function(String title)? customAppbarBuilder; final Widget Function(Future Function() onPressed, String label)? nextButtonBuilder; - final Widget Function(VoidCallback onPressed, String label)? + final Widget? Function(VoidCallback onPressed, String label)? previousButtonBuilder; final Color? backgroundColor;