feat: add auth drop down field

This commit is contained in:
FahadFahim71 2024-02-06 16:28:51 +01:00
parent f328df84dd
commit 7abb060306
3 changed files with 120 additions and 53 deletions

View file

@ -11,6 +11,7 @@ export 'src/model/auth_field.dart';
export 'src/model/auth_step.dart'; export 'src/model/auth_step.dart';
export 'src/model/auth_text_field.dart'; export 'src/model/auth_text_field.dart';
export 'src/model/auth_bool_field.dart'; export 'src/model/auth_bool_field.dart';
export 'src/model/auth_drop_down.dart';
export 'src/registration_screen.dart'; export 'src/registration_screen.dart';
export 'src/service/registration_repository.dart'; export 'src/service/registration_repository.dart';
export 'package:flutter_input_library/flutter_input_library.dart' export 'package:flutter_input_library/flutter_input_library.dart'

View file

@ -149,71 +149,78 @@ class _AuthScreenState extends State<AuthScreen> {
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 15.0, top: 15.0,
bottom: 30.0, bottom: 30.0,
left: 30.0,
right: 30.0,
), ),
child: Row( child: Column(
mainAxisAlignment:
(widget.previousButtonBuilder != null &&
previousButton == null)
? MainAxisAlignment.spaceAround
: widget.steps.first != step
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.end,
children: [ children: [
if (widget.steps.first != step) Row(
if (widget.previousButtonBuilder == null) ...[ mainAxisAlignment: MainAxisAlignment.center,
ElevatedButton( children: [
onPressed: onPrevious, if (widget.steps.first != step)
child: Row( if (widget.previousButtonBuilder == null) ...[
children: [ ElevatedButton(
const Icon( onPressed: onPrevious,
Icons.arrow_back, child: Row(
size: 18, 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), ] else if (previousButton != null) ...[
child: Text(widget.previousBtnTitle), Padding(
), padding: const EdgeInsets.all(8.0),
], child: previousButton,
), )
), ],
] else if (previousButton != null) ...[ Padding(
previousButton padding: const EdgeInsets.all(8.0),
], child: widget.nextButtonBuilder?.call(
widget.nextButtonBuilder?.call( () async {
() async { await onNext(step);
await onNext(step); },
},
widget.steps.last == step
? widget.submitBtnTitle
: widget.nextBtnTitle,
) ??
ElevatedButton(
onPressed: () async {
await onNext(step);
},
child: Row(
children: [
Text(
widget.steps.last == step widget.steps.last == step
? widget.submitBtnTitle ? widget.submitBtnTitle
: widget.nextBtnTitle, : widget.nextBtnTitle,
), ) ??
const Padding( ElevatedButton(
padding: EdgeInsets.only(left: 4.0), onPressed: () async {
child: Icon( await onNext(step);
Icons.arrow_forward, },
size: 18, 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!,
], ],
), ),
], ],

View 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;
},
),
);
}
}