-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocomplete.dart
33 lines (30 loc) · 1.03 KB
/
autocomplete.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class AutoCompleteWidget extends StatelessWidget {
const AutoCompleteWidget({super.key});
static const List<String> fruits = ['apple', 'banana', 'melon'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("AutoComplete"),
),
body: Autocomplete<String>(
optionsBuilder: (textEditingValue) {
if (textEditingValue.toString() == '') {
return const Iterable<String>.empty();
}
return fruits.where((element) {
return element.contains(textEditingValue.text.toLowerCase());
});
},
onSelected: (option) {
SystemChannels.textInput.invokeMethod('TextInput.hide');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('The $option was selected'),
));
},
));
}
void showInSnackBar(String value) {}
}