From 0f28c7084ec20977a2dd34d177a9393459f455c2 Mon Sep 17 00:00:00 2001 From: CodeThomnics Date: Wed, 14 Feb 2024 20:04:22 +0100 Subject: [PATCH] bugfix: Fix flex overflow, add own padding and alignment option for buttons Closes: #14 --- lib/src/auth_screen.dart | 177 +++++++++++------------ lib/src/config/registration_options.dart | 2 + lib/src/registration_screen.dart | 1 + 3 files changed, 86 insertions(+), 94 deletions(-) diff --git a/lib/src/auth_screen.dart b/lib/src/auth_screen.dart index 511bf6e..c2081b7 100644 --- a/lib/src/auth_screen.dart +++ b/lib/src/auth_screen.dart @@ -16,6 +16,7 @@ class AuthScreen extends StatefulWidget { required this.previousBtnTitle, required this.onFinish, this.customAppBar, + this.buttonMainAxisAlignment, this.customBackgroundColor, this.nextButtonBuilder, this.previousButtonBuilder, @@ -38,6 +39,7 @@ class AuthScreen extends StatefulWidget { final String nextBtnTitle; final String previousBtnTitle; final AppBar? customAppBar; + final MainAxisAlignment? buttonMainAxisAlignment; final Color? customBackgroundColor; final Widget Function(Future Function()? onPressed, String label, int step, bool enabled)? nextButtonBuilder; @@ -170,7 +172,7 @@ class _AuthScreenState extends State { ), ), ], - Expanded( + Flexible( flex: widget.formFlex ?? 3, child: Column( children: [ @@ -191,103 +193,90 @@ class _AuthScreenState extends State { ], ), ), - Padding( - padding: EdgeInsets.only( - top: 15.0, - bottom: 30.0, - left: widget.previousButtonBuilder == null && - widget.steps.first != widget.steps[i] - ? 30.0 - : 0.0, - right: widget.nextButtonBuilder == null && - widget.previousButtonBuilder == null - ? 30.0 - : 0.0, - ), - child: Column( - children: [ - Row( - mainAxisAlignment: - (widget.previousButtonBuilder != null && - widget.previousButtonBuilder?.call( - onPrevious, - widget.previousBtnTitle, - i, - ) == - null) - ? MainAxisAlignment.spaceAround - : widget.steps.first != widget.steps[i] - ? MainAxisAlignment.spaceBetween - : MainAxisAlignment.end, - children: [ - if (widget.previousButtonBuilder == null) ...[ - if (widget.steps.first != widget.steps[i]) - ElevatedButton( - onPressed: onPrevious, - child: Row( - children: [ - const Icon( - Icons.arrow_back, + Column( + children: [ + Row( + mainAxisAlignment: + widget.buttonMainAxisAlignment != null + ? widget.buttonMainAxisAlignment! + : (widget.previousButtonBuilder != null && + widget.previousButtonBuilder?.call( + onPrevious, + widget.previousBtnTitle, + i, + ) == + null) + ? MainAxisAlignment.start + : widget.steps.first != widget.steps[i] + ? MainAxisAlignment.center + : MainAxisAlignment.end, + children: [ + if (widget.previousButtonBuilder == null) ...[ + if (widget.steps.first != widget.steps[i]) + 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 (widget.previousButtonBuilder?.call( + onPrevious, widget.previousBtnTitle, i) != + null) ...[ + widget.previousButtonBuilder! + .call(onPrevious, widget.previousBtnTitle, i)! + ], + widget.nextButtonBuilder?.call( + !_formValid + ? null + : () async { + await onNext(widget.steps[i]); + }, + widget.steps.last == widget.steps[i] + ? widget.submitBtnTitle + : widget.nextBtnTitle, + i, + _formValid, + ) ?? + ElevatedButton( + onPressed: !_formValid + ? null + : () async { + await onNext(widget.steps[i]); + }, + child: Row( + children: [ + Text( + widget.steps.last == widget.steps[i] + ? widget.submitBtnTitle + : widget.nextBtnTitle, + ), + const Padding( + padding: EdgeInsets.only(left: 4.0), + child: Icon( + Icons.arrow_forward, size: 18, ), - Padding( - padding: - const EdgeInsets.only(left: 4.0), - child: Text(widget.previousBtnTitle), - ), - ], - ), + ), + ], ), - ] else if (widget.previousButtonBuilder?.call( - onPrevious, widget.previousBtnTitle, i) != - null) ...[ - widget.previousButtonBuilder! - .call(onPrevious, widget.previousBtnTitle, i)! - ], - widget.nextButtonBuilder?.call( - !_formValid - ? null - : () async { - await onNext(widget.steps[i]); - }, - widget.steps.last == widget.steps[i] - ? widget.submitBtnTitle - : widget.nextBtnTitle, - i, - _formValid, - ) ?? - ElevatedButton( - onPressed: !_formValid - ? null - : () async { - await onNext(widget.steps[i]); - }, - child: Row( - children: [ - Text( - widget.steps.last == widget.steps[i] - ? widget.submitBtnTitle - : widget.nextBtnTitle, - ), - const Padding( - padding: EdgeInsets.only(left: 4.0), - child: Icon( - Icons.arrow_forward, - size: 18, - ), - ), - ], - ), - ), - ], + ), + ], + ), + if (widget.loginButton != null) + Padding( + padding: const EdgeInsets.only(top: 20.0), + child: widget.loginButton!, ), - if (widget.loginButton != null) - Padding( - padding: const EdgeInsets.only(top: 20.0), - child: widget.loginButton!, - ), - ], - ), + ], ), ], ), diff --git a/lib/src/config/registration_options.dart b/lib/src/config/registration_options.dart index 7ba7d6c..01abe48 100644 --- a/lib/src/config/registration_options.dart +++ b/lib/src/config/registration_options.dart @@ -17,6 +17,7 @@ class RegistrationOptions { this.customAppbarBuilder, this.nextButtonBuilder, this.previousButtonBuilder, + this.buttonMainAxisAlignment, this.backgroundColor, this.titleWidget, this.loginButton, @@ -32,6 +33,7 @@ class RegistrationOptions { int step, bool enabled)? nextButtonBuilder; final Widget? Function(VoidCallback onPressed, String label, int step)? previousButtonBuilder; + final MainAxisAlignment? buttonMainAxisAlignment; final Color? backgroundColor; Widget? titleWidget; Widget? loginButton; diff --git a/lib/src/registration_screen.dart b/lib/src/registration_screen.dart index eb3dece..303ec6c 100644 --- a/lib/src/registration_screen.dart +++ b/lib/src/registration_screen.dart @@ -52,6 +52,7 @@ class RegistrationScreen extends StatelessWidget { previousBtnTitle: translations.previousStepBtn, nextButtonBuilder: registrationOptions.nextButtonBuilder, previousButtonBuilder: registrationOptions.previousButtonBuilder, + buttonMainAxisAlignment: registrationOptions.buttonMainAxisAlignment, customBackgroundColor: registrationOptions.backgroundColor, titleWidget: registrationOptions.titleWidget, loginButton: registrationOptions.loginButton,