forked from eatvio/eatvio_app
81 lines
2.6 KiB
Dart
81 lines
2.6 KiB
Dart
/*
|
|
class CustomTextFormField extends StatelessWidget {
|
|
// ...
|
|
|
|
final AutocompleteOptions<String> autocompleteOptions;
|
|
|
|
const CustomTextFormField({
|
|
// ... (остальные параметры)
|
|
required this.autocompleteOptions,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return alignment != null
|
|
? Align(
|
|
alignment: alignment ?? Alignment.center,
|
|
child: autocompleteFieldWidget,
|
|
)
|
|
: autocompleteFieldWidget;
|
|
}
|
|
|
|
Widget get autocompleteFieldWidget => SizedBox(
|
|
width: width ?? double.maxFinite,
|
|
child: Autocomplete<String>(
|
|
optionsBuilder: (TextEditingValue textEditingValue) {
|
|
if (textEditingValue.text == '') {
|
|
return const Iterable<String>.empty();
|
|
}
|
|
return autocompleteOptions.options.where((String option) {
|
|
return option
|
|
.toLowerCase()
|
|
.contains(textEditingValue.text.toLowerCase());
|
|
});
|
|
},
|
|
onSelected: (String value) {
|
|
controller?.text = value;
|
|
onChanged?.call(value);
|
|
},
|
|
fieldViewBuilder: (BuildContext context,
|
|
TextEditingController textEditingController,
|
|
FocusNode focusNode,
|
|
VoidCallback onFieldSubmitted) {
|
|
return TextFormField(
|
|
controller: textEditingController,
|
|
focusNode: focusNode,
|
|
autofocus: autofocus!,
|
|
style: textStyle ?? theme.textTheme.titleMedium,
|
|
obscureText: obscureText!,
|
|
textInputAction: textInputAction,
|
|
maxLines: maxLines ?? 1,
|
|
decoration: decoration,
|
|
validator: validator,
|
|
keyboardType: keyboardType,
|
|
onSaved: onSaved,
|
|
onChanged: onChanged,
|
|
inputFormatters: inputFormatters,
|
|
initialValue: initialValue,
|
|
onFieldSubmitted: (_) => onFieldSubmitted(),
|
|
);
|
|
},
|
|
optionsViewBuilder: (BuildContext context,
|
|
AutocompleteOnSelected<String> onSelected,
|
|
Iterable<String> options) {
|
|
return Material(
|
|
elevation: 4.0,
|
|
child: ListView(
|
|
children: options.map((String option) {
|
|
return ListTile(
|
|
title: Text(option),
|
|
onTap: () {
|
|
onSelected(option);
|
|
},
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}*/
|