mysearch 0.1.7 copy "mysearch: ^0.1.7" to clipboard
mysearch: ^0.1.7 copied to clipboard

A flutter plugin for information on government services and bangla search

example/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mysearch/mysearch.dart';
import 'package:mysearch/model.dart';

void main() => runApp(const MyMaterialApp());

class MyMaterialApp extends StatelessWidget {
  const MyMaterialApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'MySearch App',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('MySearch App'),
        actions: [
          // Navigate to the Search Screen
          IconButton(
              onPressed: () => Navigator.of(context)
                  .push(MaterialPageRoute(builder: (_) => const Searchpage())),
              icon: const Icon(Icons.search))
        ],
      ),
    );
  }
}

class Searchpage extends StatefulWidget {
  const Searchpage({Key? key}) : super(key: key);

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

class _SearchpageState extends State<Searchpage> {
  Future<List<SearchResultItem>>? _futureSearchResultItem;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 0,
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          children: <Widget>[
            Container(
              decoration: const BoxDecoration(boxShadow: <BoxShadow>[
                BoxShadow(
                    color: Colors.black12,
                    blurRadius: 2.0,
                    offset: Offset(0.0, 0.75))
              ], color: Colors.white),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                      flex: 10,
                      child: Center(
                        child: Padding(
                          padding: const EdgeInsets.fromLTRB(0, 4, 0, 4),
                          child: MySearchField(
                            searchIndex:0,
                            searchSize:50,
                            source: "www.mygov.bd",//"www.mygov.bd","training.mygov.bd"
                            textFieldConfiguration: TextFieldConfiguration(
                              autofocus: true,
                              style: DefaultTextStyle.of(context)
                                  .style
                                  .copyWith(
                                    fontSize: 14,
                                    fontStyle: FontStyle.normal,
                                    color: const Color.fromRGBO(15, 17, 23, 1),
                                    fontWeight: FontWeight.w500,
                                  ),
                              decoration: const InputDecoration(
                                border: InputBorder.none,
                              ),
                            ),
                            onSearchResultFound:
                                (List<SearchResultItem> searchResult) {
                              _futureSearchResultItem =
                                  Future<List<SearchResultItem>>.value(
                                      searchResult);
                              setState(() {});
                            },
                          ),
                        ),
                      )),
                ],
              ),
            ),
            const SizedBox(
              height: 10.0,
            ),
            (_futureSearchResultItem == null)
                ? const Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Text("Search Anything"),
                  )
                : Flexible(
                    child: Container(
                    child: buildFutureBuilder(),
                  ))
          ],
        ),
      ),
    );
  }

  FutureBuilder<List<SearchResultItem>> buildFutureBuilder() {
    return FutureBuilder<List<SearchResultItem>>(
      future: _futureSearchResultItem,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return ListView.builder(
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: snapshot.data!.length,
            itemBuilder: (context, index) {
              SearchResultItem searchItem = snapshot.data![index];
              return Container(
                padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 12.0),
                color: Colors.white,
                child: Column(children: <Widget>[
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Container(
                        alignment: Alignment.center,
                        child: const Padding(
                          padding: EdgeInsets.fromLTRB(12, 4, 8, 0),
                          child: Icon(
                            Icons.receipt_rounded,
                            size: 16,
                            color: Color.fromRGBO(15, 17, 23, 0.4),
                          ),
                        ),
                      ),
                      Flexible(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            const SizedBox(
                              height: 4.0,
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                searchItem.name,
                                style: const TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Colors.grey),
                              ),
                            ),
                            const SizedBox(
                              height: 4.0,
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                searchItem.service_id,
                                style: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    color: Colors.grey,
                                    fontSize: 12),
                                textAlign: TextAlign.left,
                              ),
                            ),
                            const SizedBox(
                              height: 4.0,
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                "Department : ${searchItem.department}",
                                style: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    color: Colors.grey),
                              ),
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                "Office : ${searchItem.office}",
                                style: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    color: Colors.grey),
                              ),
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                "Service Sector : ${searchItem.service_sector}",
                                style: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    color: Colors.grey),
                              ),
                            ),
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                "Source : ${searchItem.source}",
                                style: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    color: Colors.grey),
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  )
                ]),
              );
            },
          );
        } else if (snapshot.hasError) {
          return Text('${snapshot.error}');
        }

        return const CircularProgressIndicator();
      },
    );
  }
}