mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-18 21:23:43 +02:00
feat: add auth drop down field
This commit is contained in:
parent
f328df84dd
commit
7abb060306
3 changed files with 120 additions and 53 deletions
|
@ -11,6 +11,7 @@ export 'src/model/auth_field.dart';
|
|||
export 'src/model/auth_step.dart';
|
||||
export 'src/model/auth_text_field.dart';
|
||||
export 'src/model/auth_bool_field.dart';
|
||||
export 'src/model/auth_drop_down.dart';
|
||||
export 'src/registration_screen.dart';
|
||||
export 'src/service/registration_repository.dart';
|
||||
export 'package:flutter_input_library/flutter_input_library.dart'
|
||||
|
|
|
@ -149,71 +149,78 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||
padding: const EdgeInsets.only(
|
||||
top: 15.0,
|
||||
bottom: 30.0,
|
||||
left: 30.0,
|
||||
right: 30.0,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
(widget.previousButtonBuilder != null &&
|
||||
previousButton == null)
|
||||
? MainAxisAlignment.spaceAround
|
||||
: widget.steps.first != step
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.end,
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.steps.first != step)
|
||||
if (widget.previousButtonBuilder == null) ...[
|
||||
ElevatedButton(
|
||||
onPressed: onPrevious,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.arrow_back,
|
||||
size: 18,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.steps.first != step)
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4.0),
|
||||
child: Text(widget.previousBtnTitle),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
] else if (previousButton != null) ...[
|
||||
previousButton
|
||||
],
|
||||
widget.nextButtonBuilder?.call(
|
||||
() async {
|
||||
await onNext(step);
|
||||
},
|
||||
widget.steps.last == step
|
||||
? widget.submitBtnTitle
|
||||
: widget.nextBtnTitle,
|
||||
) ??
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await onNext(step);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
),
|
||||
] else if (previousButton != null) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: previousButton,
|
||||
)
|
||||
],
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: widget.nextButtonBuilder?.call(
|
||||
() async {
|
||||
await onNext(step);
|
||||
},
|
||||
widget.steps.last == step
|
||||
? widget.submitBtnTitle
|
||||
: widget.nextBtnTitle,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 4.0),
|
||||
child: Icon(
|
||||
Icons.arrow_forward,
|
||||
size: 18,
|
||||
) ??
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await onNext(step);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.steps.last == step
|
||||
? 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) widget.loginButton!,
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
59
lib/src/model/auth_drop_down.dart
Normal file
59
lib/src/model/auth_drop_down.dart
Normal file
|
@ -0,0 +1,59 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_registration/flutter_registration.dart';
|
||||
|
||||
class AuthDropdownField extends AuthField {
|
||||
AuthDropdownField({
|
||||
required super.name,
|
||||
required this.items,
|
||||
required this.onChanged,
|
||||
this.dropdownDecoration,
|
||||
this.padding = const EdgeInsets.all(8.0),
|
||||
this.textStyle,
|
||||
this.icon = const Icon(Icons.keyboard_arrow_down),
|
||||
required super.value,
|
||||
}) {
|
||||
selectedValue = value ?? items.first;
|
||||
}
|
||||
|
||||
final List<String> items;
|
||||
final Function(String?) onChanged;
|
||||
String? selectedValue;
|
||||
final InputDecoration? dropdownDecoration;
|
||||
final EdgeInsets padding;
|
||||
final TextStyle? textStyle;
|
||||
final Icon icon;
|
||||
|
||||
@override
|
||||
Widget build() {
|
||||
return Padding(
|
||||
padding: padding,
|
||||
child: DropdownButtonFormField<String>(
|
||||
icon: icon,
|
||||
style: textStyle,
|
||||
value: selectedValue,
|
||||
decoration: dropdownDecoration,
|
||||
items: items.map((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (newValue) {
|
||||
selectedValue = newValue;
|
||||
onChanged(newValue);
|
||||
},
|
||||
validator: (value) {
|
||||
if (validators.isNotEmpty) {
|
||||
for (var validator in validators) {
|
||||
var output = validator(value);
|
||||
if (output != null) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue