Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

Autocomplete Widget in Flutter

import 'package:flutter/material.dart'
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Autocomplete Basic'),
        ),
        body: const Center(
          child: Padding(
            padding: EdgeInsets.all(10.0),
            child: AutocompleteText(),
          ),
        ),
      ),
    );
  }
}

class AutocompleteText extends StatelessWidget {
  const AutocompleteText({Key? key}) : super(key: key);
  static const List<String> data = <String>[
    'Adrian',
    'Axel',
    'jhonn',
    'bobcat',
    'chameleon',
    'Oliver',
    'William',
    'Ethan',
    'Everett',
    'Jayden',
  ];

  @override
  Widget build(BuildContext context) {
    return Autocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        if (textEditingValue.text == '') {
          return const Iterable<String>.empty();
        }
        return data.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      onSelected: (String selection) {
        debugPrint('You just selected $selection');
      },
    );
  }
};
Source by www.linkedin.com #
 
PREVIOUS NEXT
Tagged: #Autocomplete #Widget #Flutter
ADD COMMENT
Topic
Name
9+8 =