forked from eatvio/eatvio_app
feat(diary): Custom autocomplete
This commit is contained in:
@@ -281,32 +281,70 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
})),
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: TypeAheadField<dynamic>(
|
||||
controller: state.productNameController,
|
||||
suggestionsCallback: (search) => state.autocompleteList,
|
||||
builder: (context, controller, focusNode) {
|
||||
return CustomTextFormField(
|
||||
hintText: "Введите названия продукта",
|
||||
controller: controller,
|
||||
onChanged: (value) {
|
||||
print(state.autocompleteList);
|
||||
if (value.length > 3) {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.add(ProductInput(value));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, product) {
|
||||
return ListTile(
|
||||
title: Text(product),
|
||||
subtitle: Text(product),
|
||||
);
|
||||
},
|
||||
onSelected: (product) {},
|
||||
)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: RawAutocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text == '') {
|
||||
return const Iterable<String>.empty();
|
||||
}
|
||||
return Future<Iterable<String>>.value(state.autocompleteList
|
||||
?.map((dynamic item) => item as String)
|
||||
.toList()
|
||||
.where((String option) {
|
||||
return true;
|
||||
}));
|
||||
},
|
||||
fieldViewBuilder: (
|
||||
BuildContext context,
|
||||
TextEditingController textEditingController,
|
||||
FocusNode focusNode,
|
||||
VoidCallback onFieldSubmitted,
|
||||
) {
|
||||
return CustomTextFormField(
|
||||
hintText: "Введите названия продукта",
|
||||
controller: state.productNameController,
|
||||
onChanged: (value) {
|
||||
print(state.autocompleteList);
|
||||
if (value.length > 3) {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.add(ProductInput(value));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
optionsViewBuilder: (
|
||||
BuildContext context,
|
||||
AutocompleteOnSelected<String> onSelected,
|
||||
Iterable<String> options,
|
||||
) {
|
||||
return Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Material(
|
||||
elevation: 4.0,
|
||||
child: SizedBox(
|
||||
height: 200.0,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
itemCount: options.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final String option = options.elementAt(index);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
onSelected(option);
|
||||
},
|
||||
child: ListTile(
|
||||
title: Text(option),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
|
||||
Reference in New Issue
Block a user