forking_search_bar 3.0.0 copy "forking_search_bar: ^3.0.0" to clipboard
forking_search_bar: ^3.0.0 copied to clipboard

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

example/lib/main.dart

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

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

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: 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: ForkingSearchBar(
                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'))));
  }
}
0
likes
150
points
20
downloads

Publisher

unverified uploader

Weekly Downloads

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 forking_search_bar