passo_mobile_app/lib/widgets/passo/custom_formBuilder_fields.dart

62 lines
2.0 KiB
Dart
Raw Normal View History

2023-07-28 02:35:36 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:unit2/theme-data.dart/form-style.dart';
2024-07-11 01:27:35 +00:00
Widget customTextField(
String labelText, String hintText, String keyText, TextInputType type) {
2023-07-28 02:35:36 +00:00
return Container(
margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
child: FormBuilderTextField(
name: keyText,
2024-07-11 01:27:35 +00:00
keyboardType: type,
2023-07-28 02:35:36 +00:00
decoration: normalTextFieldStyle(labelText, hintText),
validator: FormBuilderValidators.compose([]),
),
);
}
Widget customDropDownField(String labelText, String hintText, String keyText,
List<String> dropdownItems) {
2023-09-01 03:22:48 +00:00
// Create a Set to keep track of unique values
Set<String> uniqueItems = {};
// Iterate through the dropdownItems list to filter out duplicates
for (var item in dropdownItems) {
uniqueItems.add(item);
}
// Convert the Set back to a List to use for DropdownMenuItem
List<String> filteredItems = uniqueItems.toList();
2023-07-28 02:35:36 +00:00
return Container(
margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
child: FormBuilderDropdown<String?>(
2023-09-01 03:22:48 +00:00
name: keyText,
autofocus: false,
decoration: normalTextFieldStyle(labelText, hintText),
items: filteredItems
.map((item) => DropdownMenuItem(
value: item,
child: Text(item),
))
.toList(),
),
2023-07-28 02:35:36 +00:00
);
}
Widget customDatTimePicker(String labelText, String hintText, String keyText) {
return Container(
margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
child: FormBuilderDateTimePicker(
name: keyText,
initialEntryMode: DatePickerEntryMode.calendarOnly,
initialValue: DateTime.now(),
inputType: InputType.date,
decoration: normalTextFieldStyle(labelText, hintText),
initialTime: const TimeOfDay(hour: 8, minute: 0),
// locale: const Locale.fromSubtags(languageCode: 'fr'),
),
);
}