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,17 +149,11 @@ 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: children: [
(widget.previousButtonBuilder != null && Row(
previousButton == null) mainAxisAlignment: MainAxisAlignment.center,
? MainAxisAlignment.spaceAround
: widget.steps.first != step
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.end,
children: [ children: [
if (widget.steps.first != step) if (widget.steps.first != step)
if (widget.previousButtonBuilder == null) ...[ if (widget.previousButtonBuilder == null) ...[
@ -172,16 +166,22 @@ class _AuthScreenState extends State<AuthScreen> {
size: 18, size: 18,
), ),
Padding( Padding(
padding: const EdgeInsets.only(left: 4.0), padding:
const EdgeInsets.only(left: 4.0),
child: Text(widget.previousBtnTitle), child: Text(widget.previousBtnTitle),
), ),
], ],
), ),
), ),
] else if (previousButton != null) ...[ ] else if (previousButton != null) ...[
previousButton Padding(
padding: const EdgeInsets.all(8.0),
child: previousButton,
)
], ],
widget.nextButtonBuilder?.call( Padding(
padding: const EdgeInsets.all(8.0),
child: widget.nextButtonBuilder?.call(
() async { () async {
await onNext(step); await onNext(step);
}, },
@ -210,10 +210,17 @@ class _AuthScreenState extends State<AuthScreen> {
], ],
), ),
), ),
),
],
),
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;
},
),
);
}
}