Autocomplete Class

import "package:flutter/material.dart";

void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Autocomplete Class Practice",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const AutoCompletePractice(),
);
}
}
class AutoCompletePractice extends StatelessWidget
{
const AutoCompletePractice({super.key});

static const List<String> suggestionsList = [
"toy", "Toy", "apple", "Apple", "banana", "Banana", "mango", "Mango", "cat", "Cat", "play",
"Play", "game", "Game", "microsoft", "Microsoft", "google", "Google", "zebra", "Zebra", "rat",
"Rat", "umbrella", "Umbrella", "pineapple", "Pineapple", "tomorrow", "Tomorrow", "yesterday",
"Yesterday", "english", "English", "hindi", "Hindi", "xerox", "Xerox", "firm", "Firm", "owner",
"Owner", "honor", "Honor", "departure", "Departure", "particular", "Particular", "alias", "Alias",
"released", "Released", "allowance", "Allowance", "abstract", "Abstract", "prophecy", "Prophecy",
"devotion", "Devotion", "embrace", "Embrace", "invaluable", "Invaluable", "sibling", "Sibling",
"machine", "Machine", "peeling", "Peeling", "diplomatic", "Diplomatic", "pending", "Pending",
"elite", "Elite", "commitment", "Commitment", "irrational", "Irrational", "reliance", "Reliance",
"countless", "Countless", "sustainable", "Sustainable", "forefront", "Forefront", "front", "Front",
"foreground", "Foreground", "vanguard", "Vanguard", "initiate", "Initiate", "groundbreaking",
"Groundbreaking", "wanted", "Wanted", "want", "Want", "Laravel", "laravel", "Dart", "dart",
"Kotlin", "kotlin", "react js", "React Js", "node js", "Node Js", "Oops", "oops", "software",
"Software", "android", "Android", "php", "Php", "hour", "Hour", "morning", "Morning", "next day",
"Next Day", "day", "Day", "disclose", "Disclose", "monk", "Monk","brother", "Brother", "notice",
"Notice", "advice", "Advice", "possessive", "Possessive", "naps", "Naps", "zoom", "Zoom", "zeal",
"Zeal", "enthusiasm", "Enthusiasm", "passion", "Passion", "zest", "Zest","zip", "Zip", "zap", "Zap",
"behavior", "Behavior", "transaction", "Transaction", "character", "Character", "compare", "Compare",
"etiquette", "Etiquette", "quashes", "Quashes", "procedure", "Procedure", "legal", "Legal", "process",
"Process", "especially", "Especially", "reject", "Reject", "cancel", "Cancel", "override", "Override",
"void", "Void", "fruits", "Fruits", "fruitless", "Fruitless", "vain", "Vain", "vainglorious",
"Vainglorious", "much", "Much", "mutual", "Mutual"
];

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Autocomplete Class Practice"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Center(
child: Container(
width: 300.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text("Type below to autocomplete the following result: ",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
if(textEditingValue.text.isEmpty)
{
return const Iterable<String>.empty();
}
final String query = textEditingValue.text.toLowerCase();
return suggestionsList.where((String option) {
return option.toLowerCase().contains(query);
});
},
onSelected: (String selection) {
debugPrint("You just selected: $selection");
},
),
],
),
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter