flutter_easy_search_bar 0.0.2 copy "flutter_easy_search_bar: ^0.0.2" to clipboard
flutter_easy_search_bar: ^0.0.2 copied to clipboard

AppBar with animated search functionality that can be used as regular or floating AppBar

example/lib/main.dart

import 'package:flutter_easy_search_bar/flutter_easy_search_bar.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyHomePage());
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String searchValue = '';
  final List<String> _suggestions = [
    'Afeganistan',
    'Albania',
    'Algeria',
    'Australia',
    'Brazil',
    'German',
    'Madagascar',
    'Mozambique',
    'Portugal',
    'Zambia'
  ];

  Future<List<String>> _fetchSuggestions(String searchValue) async {
    await Future.delayed(const Duration(milliseconds: 750));

    return _suggestions.where((element) {
      return element.toLowerCase().contains(searchValue.toLowerCase());
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',
      theme: ThemeData(primarySwatch: Colors.orange),
      home: Scaffold(
        appBar: EasySearchBar(
          title: const Text('Example'),
          onSearch: (value) => setState(() => searchValue = value),
          actions: [
            IconButton(icon: const Icon(Icons.person), onPressed: () {})
          ],
          asyncSuggestions: (value) async => await _fetchSuggestions(value),
        ),
        drawer: Drawer(
          child: ListView(
            padding: EdgeInsets.zero,
            children: [
              const DrawerHeader(
                decoration: BoxDecoration(
                  color: Colors.blue,
                ),
                child: Text('Drawer Header'),
              ),
              ListTile(
                  title: const Text('Item 1'),
                  onTap: () => Navigator.pop(context)),
              ListTile(
                  title: const Text('Item 2'),
                  onTap: () => Navigator.pop(context))
            ],
          ),
        ),
        body: Center(
          child: Text('Value: $searchValue'),
        ),
      ),
    );
  }
}
5
likes
150
pub points
74%
popularity

Publisher

unverified uploader

AppBar with animated search functionality that can be used as regular or floating AppBar

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on flutter_easy_search_bar