multi_search_flutter 0.0.1 icon indicating copy to clipboard operation
multi_search_flutter: ^0.0.1 copied to clipboard

A new Flutter package for multi serach view.

example/lib/main.dart

import 'dart:async';

import 'package:example/image_view.dart';
import 'package:flutter/material.dart';
import 'package:multi_search_flutter/multi_search_flutter.dart';
import 'package:multi_search_flutter/search_indicator_style_enum.dart';

import 'list_generator.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late StreamController<List<ImageView>> _streamList;
  late List<ImageView> imagesList;

  @override
  void initState() {
    super.initState();
    _streamList = StreamController<List<ImageView>>();
    imagesList = getImages();
    _streamList.sink.add(imagesList);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: true,
        child: Column(
          children: [
            Align(
                alignment: Alignment.centerLeft,
                child: Padding(
                  padding: const EdgeInsets.all(18.0),
                  child: Text(
                    'Explore',
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 40),
                  ),
                )),
            SizedBox(
              height: 20,
            ),
            MultiSearchView(
              inputHint: 'type your text',
              onSelectItem: (value) {
                filterList(value);
              },
              onSearchComplete: (value) {
                filterList(value);
              },
              onDeleteAlternative: (value) {
                filterList(value);
              },
              onItemDeleted: (value) {
                print(value);
              },
              onSearchCleared: () {
                removeFilter();
              },
            ),
            SizedBox(
              height: 30,
            ),
            Expanded(
              child: StreamBuilder(
                  stream: _streamList.stream,
                  builder: (context, AsyncSnapshot<List<ImageView>>? snapshot) {
                    return ListView(
                        children: ((snapshot != null && snapshot.data != null)
                                ? ((snapshot.data?.isNotEmpty ?? false)
                                    ? (snapshot.data
                                        ?.map((e) => Container(
                                            height: 180,
                                            width: MediaQuery.of(context)
                                                .size
                                                .width,
                                            child: e.image))
                                        .toList())
                                    : [])
                                : []) ??
                            []);
                  }),
            ),
          ],
        ),
      ),
    );
  }

  void filterList(value) {
    _streamList.sink.add(imagesList
        .where((element) => element.name?.contains(value) ?? false)
        .toList());
  }

  void removeFilter() {
    _streamList.sink.add(imagesList);
  }

  @override
  void dispose() {
    _streamList.close();
    super.dispose();
  }
}
6
likes
100
pub points
38%
popularity

Publisher

unverified uploader

A new Flutter package for multi serach view.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on multi_search_flutter