Searchhelperexample - SearchHelper - code wrapper for searching functionality

Overview

DotCoder

Overview


SearchHelper is code wrapper for searching functionality developed by DOTCODER. It is kind of help to developer to perform searching easy.

How it work's:

SearchHelper is class that has three static methods. 1- wordSearch() 2- stringInstantSearch() 3- searchModel()

1st and 2nd method expect same Parameter to be passed. given bellow.

Parameter Description
data This parameter takes List<Map<String,dynamic>> as a data source and perform search on that data.
keys This parameter takes List<String> as a searching field like search work in title, description field.
searchWord This parameter is basically the word that need to be searched in the data.
Note:

SearchWord parameter takes dynamic value like it accepts bool, int, double and String.

How wordSearch() and stringInstantSearch() works:

It takes List<Map<String,dynamic>> as data parameter, List<String> as properties parameter and searchWord parameter takes dynamic value. It returns List<Map<String,dynamic>> as a search result.

How searchModel() Works:

It takes List<T> as data parameter, List<String> as keys parameter, Map<String,String> as object search in each user defined model and searchWord parameter takes dynamic value. It returns List<Map<String,dynamic>> as a search result.

Important note:

Make sure that every model that you're using have it's toJson() and fromJson() methods because plugin is using it in underlying work.

Parameter Description
data This parameter takes List<T> as a data source and perform search on that data.
properties This parameter takes List<String> as a searching field like search work in title, description field.
innerObject If you want to search in a List<T> and there is another object inside T then you can use innerObject to search specific object containing model.
searchWord This parameter is basically the word that need to be searched in the data.

Getting Started

In pubspec.yaml

dependencies:
    search_helper: ^0.0.7

Code Example of 1st and 2nd method as they're same:

import 'package:search_helper/search_helper.dart';

void main(){
  
  List<Map<String,dynamic>> items = [
    {
      'name': "Osama",
      'age': 21,
      'father': "Noushad"
    },
    {
      'name': "Haseeb",
      'age': 20,
      'father': "Noushad"
    },
    {
      'name': "Shahrok",
      'age': 22,
      'father': "Noushad"
    },
    {
      'name': "Asad",
      'age': 23,
      'father': "Noushad"
    },
  ];
  
  
  List<String> keys = ['age','name','father'];
  
  
  List<Map<String,dynamic>> result = SearchHelper.stringInstantSearch(data: items,keys: keys,searchWord: 'osama');
 
}

Code Example of model based search:

1st Example:

First of all let's define our User Model. and we'll be using that User model to search for some users.

class User {
  String name;
  int age;

  User(this.name, this.age);

  Map toJson() => {
    'name': name,
    'age': age,
  };

  factory User.fromJson(dynamic json) {
    return User(json['name'] as String, json['age'] as int);
  }
}

as it is mentioned that toJson() and fromJson() is required in searching model.

Let's search over List<User>.

import 'package:search_helper/search_helper.dart';
import 'dart:convert';

void main(){
  
  
    List<User> users = [
        User('Osama',12),
        User('Haseeb',13),
        User("Shahrokh",14)
    ];
    
    List<User> filteredUsers = [];

    var result = SearchHelper.searchModel(
        data: users,
        properties: ['name',],
        searchWord: 'osama'
    );
           
    result.forEach((e){
       User u = User.fromJson(e);
       filteredUsers.add(u);
    });              
    
    
 
}

2nd example:

let's perform little deep search on another model that have tutorial information and it's author information.

so let's first create cass for Tutorial model.

class Tutorial {
  String title;
  String description;
  User? author;
  
  Tutorial(this.title, this.description, {this.author});

  Map toJson() {
  Map? author =
  this.author! != null ? this.author!.toJson() : null;

  return {
  'title': title,
  'description': description,
  'author': author,
  };
  }

  factory Tutorial.fromJson(dynamic json) {
    
      return Tutorial(
          json['title'] as String,
          json['description'] as String,
          author:
          User.fromJson(json['author'])
      );
    
  }
}

Now our Tutorial model is completed let's now use the same User class that we used above.

Let's create the search for all those tutorials whose author name is starting with osama.

import 'package:search_helper/search_helper.dart';
import 'dart:convert';

void main(){
  
  
    List<Tutorial> tutorials = [
    Tutorial('C++', "This is c++ course.",author: User('Osama', 12)),
    Tutorial('C#', "This is c# course.",author: User('Haseeb', 13)),
  ];
  
  List<Tutorial> filteredTutorials = [];

  var result = SearchHelper.searchModel(
        data: tutorials,
        innerObject: {'author': 'name'},
        searchWord: 'osama'
    );

 result.forEach((e){
       Tutorial t = Tutorial.fromJson(e);
       filteredTutorials.add(t);
    });                                    
    
}

The result that we'll be get at the end of searchModel() is List<dynamic> and then you need to convert it again to model.

That's all we've to do.

Happy Coding and Searching 🤗 .

You might also like...

Peek & Pop implementation for Flutter based on the iOS functionality of the same name.

peek_and_pop Peek & Pop implementation for Flutter based on the iOS functionality of the same name. Finally, the v1.0.0 release! More fluent, more opt

Dec 17, 2022

⚒️ A monorepo containing a collection of packages that provide useful functionality for building CLI applications in Dart.

⚒️ A monorepo containing a collection of packages that provide useful functionality for building CLI applications in Dart.

⚒️ Dart CLI Utilities A monorepo containing a collection of packages that provide useful functionality for building CLI applications in Dart. Document

Oct 17, 2022

A Todo app with full fledge functionality and Awesome Look and feel.

to_do A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

Aug 5, 2022

(Flutter)Minimal App With Offline Storage(Using HIVE) Functionality.

(Flutter)Minimal App With Offline Storage(Using HIVE) Functionality.

TaskZ (Minimal + Offline TODO List App) Minimal App With Offline Storage(Using HIVE) Functionality. Getting Started 👍 Any suggestion, improvement on

Oct 2, 2022

Dead simple WiFi connect functionality for flutter.

Flutter WiFi Connect Easily connect to a specified WiFi AP programmatically, using this plugin. import 'package:wifi_connect/wifi_connect.dart'; WifiC

Dec 7, 2022

A Stable GeoFence Library - A flutter project to provide Geo Fence functionality in Android and IOS

A Stable GeoFence Library - A flutter project to provide Geo Fence functionality in Android and IOS

A flutter project to provide Geo Fence functionality in Android and IOS Getting Started Android In your AndroidManifest.xml

Nov 15, 2022

A flutter plugin to support drag-out functionality on native platforms

A flutter plugin to support drag-out functionality on native platforms

flutter_native_drag_n_drop A flutter plugin to support the native drag and drop, especially to drag files (only files) out of the application boundary

Oct 28, 2022

A collections of packages providing additional functionality for working with bloc

Bloc Extensions A collections of packages providing additional functionality for working with bloc. Index Packages Bloc Hooks Action Blocs Contributin

Apr 19, 2022

A migration of the pandas functionality to read yahoo finance stock prices

A migration of the pandas functionality to read yahoo finance stock prices

This lib have a strong advantage on backtesting strategies as it can give all the dataframe in yahoo finance, this means that can get daily data on futures like NQ=F and ES=F since 2000 and it goes as far as getting data from 1927 on the SP500 yahoo finance symbol ^GSPC

Jan 1, 2023
Owner
Osama Qureshi
Osama Qureshi
A Dart widget for entering international telephone numbers with dropdown searching input countries

Dart Tel Input A Dart widget for entering international telephone numbers with dropdown searching input countries Getting Started Add the following li

աɨռɢӄաօռɢ 8 Oct 29, 2020
A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

PengHui Li 112 Nov 11, 2022
Flutter After Layout - Brings functionality to execute code after the first layout of a widget has been performed

Flutter After Layout - Brings functionality to execute code after the first layout of a widget has been performed, i.e. after the first frame has been displayed. Maintainer: @slightfoot

Flutter Community 432 Jan 3, 2023
This is an auction application just like eBay. Using firebase as the backend for signup & sign-in functionality. In addition to that, it's a two pages application with user bid in input and count down view.

Nilam This is an auction application just like eBay. Using firebase as the backend for signup & sign-in functionality. In addition to that, it's a two

Md. Siam 5 Nov 9, 2022
Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to

Roman Hornak 23 Feb 23, 2022
Allows send emails from flutter using native platform functionality.

flutter_email_sender Allows send emails from flutter using native platform functionality. In android it opens default mail app via intent. In iOS MFMa

Tautvydas Šidlauskas 107 Jan 3, 2023
Fwitter is an example application that demonstrates the features and functionality of Fauna.

A full introduction to this project can be found in the docs. This project is an example of how to build a 'real-world' app with highly dynamic data i

Fauna Labs 291 Dec 13, 2022
A TextField flutter package with tagging functionality.

Flutter Tagging A flutter package with tagging or multi-select functionality. Useful for adding Tag or Label Selection Forms. List<Language> _selected

Sarbagya Dhaubanjar 149 Sep 6, 2022
Dart package to support Wake-on-LAN functionality

wake_on_lan Dart library package to easily send Wake-on-LAN magic packets to devices on your local network. Getting Started wake_on_lan has three core

Jagandeep Brar 3 Oct 24, 2022
Contactus - a flutter package. The most common functionality added in any commercial app is the Developer's contact details

Contact Us The most common functionality added in any commercial app is the Developer's contact details!! So this package helps the developers to simp

Abhishek Doshi 19 Aug 4, 2022