mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-19 05:23:43 +02:00
fix: Fix button placement and added step to button builders
This commit is contained in:
parent
e112c64ee7
commit
49b9ece2d5
3 changed files with 62 additions and 53 deletions
|
@ -75,7 +75,6 @@ class _FlutterRegistrationDemoState extends State<FlutterRegistrationDemo> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RegistrationScreen(
|
return RegistrationScreen(
|
||||||
registrationOptions: RegistrationOptions(
|
registrationOptions: RegistrationOptions(
|
||||||
previousButtonBuilder: (onPressed, label) => null,
|
|
||||||
registrationRepository: ExampleRegistrationRepository(),
|
registrationRepository: ExampleRegistrationRepository(),
|
||||||
registrationSteps: steps,
|
registrationSteps: steps,
|
||||||
afterRegistration: () {
|
afterRegistration: () {
|
||||||
|
|
|
@ -35,8 +35,11 @@ class AuthScreen extends StatefulWidget {
|
||||||
final String previousBtnTitle;
|
final String previousBtnTitle;
|
||||||
final AppBar? customAppBar;
|
final AppBar? customAppBar;
|
||||||
final Color? customBackgroundColor;
|
final Color? customBackgroundColor;
|
||||||
final Widget Function(Future<void> Function(), String)? nextButtonBuilder;
|
final Widget Function(
|
||||||
final Widget? Function(VoidCallback, String)? previousButtonBuilder;
|
Future<void> Function() onPressed, String label, int step)?
|
||||||
|
nextButtonBuilder;
|
||||||
|
final Widget? Function(VoidCallback onPressed, String label, int step)?
|
||||||
|
previousButtonBuilder;
|
||||||
final Widget? titleWidget;
|
final Widget? titleWidget;
|
||||||
final Widget? loginButton;
|
final Widget? loginButton;
|
||||||
|
|
||||||
|
@ -101,11 +104,6 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var previousButton = widget.previousButtonBuilder?.call(
|
|
||||||
onPrevious,
|
|
||||||
widget.previousBtnTitle,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: widget.customBackgroundColor ?? Colors.white,
|
backgroundColor: widget.customBackgroundColor ?? Colors.white,
|
||||||
appBar: _appBar,
|
appBar: _appBar,
|
||||||
|
@ -115,7 +113,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
controller: _pageController,
|
controller: _pageController,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
for (AuthStep step in widget.steps)
|
for (var i = 0; i < widget.steps.length; i++)
|
||||||
Column(
|
Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
|
@ -130,7 +128,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
for (AuthField field in step.fields)
|
for (AuthField field in widget.steps[i].fields)
|
||||||
Align(
|
Align(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
@ -146,23 +144,36 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
top: 15.0,
|
top: 15.0,
|
||||||
bottom: 30.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(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
(widget.previousButtonBuilder != null &&
|
(widget.previousButtonBuilder != null &&
|
||||||
previousButton == null)
|
widget.previousButtonBuilder?.call(
|
||||||
|
onPrevious,
|
||||||
|
widget.previousBtnTitle,
|
||||||
|
i,
|
||||||
|
) ==
|
||||||
|
null)
|
||||||
? MainAxisAlignment.spaceAround
|
? MainAxisAlignment.spaceAround
|
||||||
: widget.steps.first != step
|
: widget.steps.first != widget.steps[i]
|
||||||
? MainAxisAlignment.spaceBetween
|
? MainAxisAlignment.spaceBetween
|
||||||
: MainAxisAlignment.end,
|
: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
if (widget.steps.first != step)
|
|
||||||
if (widget.previousButtonBuilder == null) ...[
|
if (widget.previousButtonBuilder == null) ...[
|
||||||
|
if (widget.steps.first != widget.steps[i])
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: onPrevious,
|
onPressed: onPrevious,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
@ -179,30 +190,29 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
] else if (previousButton != null) ...[
|
] else if (widget.previousButtonBuilder?.call(
|
||||||
Padding(
|
onPrevious, widget.previousBtnTitle, i) !=
|
||||||
padding: const EdgeInsets.all(8.0),
|
null) ...[
|
||||||
child: previousButton,
|
widget.previousButtonBuilder!
|
||||||
)
|
.call(onPrevious, widget.previousBtnTitle, i)!
|
||||||
],
|
],
|
||||||
Padding(
|
widget.nextButtonBuilder?.call(
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: widget.nextButtonBuilder?.call(
|
|
||||||
() async {
|
() async {
|
||||||
await onNext(step);
|
await onNext(widget.steps[i]);
|
||||||
},
|
},
|
||||||
widget.steps.last == step
|
widget.steps.last == widget.steps[i]
|
||||||
? widget.submitBtnTitle
|
? widget.submitBtnTitle
|
||||||
: widget.nextBtnTitle,
|
: widget.nextBtnTitle,
|
||||||
|
i,
|
||||||
) ??
|
) ??
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await onNext(step);
|
await onNext(widget.steps[i]);
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.steps.last == step
|
widget.steps.last == widget.steps[i]
|
||||||
? widget.submitBtnTitle
|
? widget.submitBtnTitle
|
||||||
: widget.nextBtnTitle,
|
: widget.nextBtnTitle,
|
||||||
),
|
),
|
||||||
|
@ -216,7 +226,6 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (widget.loginButton != null)
|
if (widget.loginButton != null)
|
||||||
|
|
|
@ -29,9 +29,10 @@ class RegistrationOptions {
|
||||||
final VoidCallback afterRegistration;
|
final VoidCallback afterRegistration;
|
||||||
final RegistrationRepository registrationRepository;
|
final RegistrationRepository registrationRepository;
|
||||||
final AppBar Function(String title)? customAppbarBuilder;
|
final AppBar Function(String title)? customAppbarBuilder;
|
||||||
final Widget Function(Future<void> Function() onPressed, String label)?
|
final Widget Function(
|
||||||
|
Future<void> Function() onPressed, String label, int step)?
|
||||||
nextButtonBuilder;
|
nextButtonBuilder;
|
||||||
final Widget? Function(VoidCallback onPressed, String label)?
|
final Widget? Function(VoidCallback onPressed, String label, int step)?
|
||||||
previousButtonBuilder;
|
previousButtonBuilder;
|
||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
Widget? titleWidget;
|
Widget? titleWidget;
|
||||||
|
|
Loading…
Reference in a new issue