LogoLogo
CMSGitHubSupportBook a demo
  • Documentation
  • Academy
  • Help Center
  • Welcome
  • SDKS & Frameworks
    • Web
      • Getting Started
        • Prerequisites
          • MapsIndoors
          • Map Engine Provider
            • Option 1: Get your Mapbox Access Token
            • Option 2: Get your Google Maps API Keys​
          • Map Engine Setup
        • Getting Started: MapsIndoors
      • Map Visualization
        • Highlight, Hover and Select
        • Remove Labels from Buildings and Venues
        • Change Building Outline
        • Managing Collisions Based on Zoom Level
        • 3D Maps
          • Managing your 3D Maps
        • Base Map Styling - Google Maps
        • Managing feature visibility for Mapbox
      • Wayfinding
        • Directions
        • Directions Service
          • Tailoring the directions to your specific needs
        • Directions Renderer
          • Customizing the Route Animation
        • Multi-stop navigation
          • Custom Icons
        • User's Location as Point of Origin
      • Search
        • Search Operations
        • Searching
        • Using External ID, Geospatial Joins
        • Utilizing MapsIndoors Web Components and Other Searches
      • Map Management
      • Data Visualization
        • Display Heatmap Overlay
      • Other guides
        • Authentication
          • Single Sign-On
            • SSO Configuration
            • SSO Authorisation
          • 2-Factor Authentication
          • Password Reset
        • Application User Roles
        • Custom Properties
        • Display Language
        • Language
        • User Positioning
          • Show User's Location aka. Blue Dot
          • Using Cisco DNA Spaces
        • Working with Events
        • Turn Off Collisions Based on Zoom Level
        • Remove Labels from Buildings and Venues for Web
        • Synchronizing data for a subset of venues
        • Custom Floor Selector
      • Display Rules in Practice
      • Offline Data
      • Managing map visibility
    • Android
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
        • Migrating from V3 to V4
          • Migrating to Mapbox V11
      • Directions
        • Directions Service
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Switching Solutions
      • Caching & Offline Data
      • Display Language
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Clustering
        • Location Data Sources
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Change Building Outline Color
      • Event Logging
      • Configuring a menu with AppConfig
      • Display Heatmap Overlay
      • Custom Properties
      • Custom Floor Selector
      • External IDs
      • User Positioning
        • Show User's Location aka. Blue Dot
        • Using Cisco DNA Spaces
        • Using Google Fused Location Provider
        • Using Indoor Atlas
      • Authentication
        • Single Sign-On
          • SSO Configuration
          • SSO Authorisation
        • 2-Factor Authentication
        • Password Reset
      • Display Rules in Practice
        • Label styling through Display Rules
      • Highlight and Select
    • iOS
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Getting Directions
        • Migrating from v3 to v4
      • Directions
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Directions Service
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Caching & Offline Data
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Custom Floor Selector
      • Change Building Outline Color
      • Custom Map Padding
      • Custom Properties
      • Display Rules in Practice
        • Label styling through Display Rules
      • Switching Solutions
      • Show User's Location aka. Blue Dot
        • Using Indoor Atlas
        • Using Cisco DNA Spaces
      • Highlight and Select
      • Display Language
    • React Native
      • Getting Started
        • Prerequisites
        • Project Setup
        • Displaying a Map
        • Creating a Search Experience
        • Getting Directions
        • Enabling Live Data
      • Showing Blue Dot
    • Flutter
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
      • Migration Guide
    • Integration API
      • Integration API Access
        • Access with Swagger
        • Access with Postman
        • Access with Python
        • Client credentials flow
      • Data Description
      • Reverse Geocoding
      • Route Access
      • OpenAPI Specification
    • Built-In Map Edits
      • Getting started
      • Authentication
      • Release notes
      • Reference docs
  • Products
    • Product Overview
    • CMS
      • Interface Overview
      • Display Rules
      • Location Types
      • Categories
      • Media Library
        • 2D Models and Icons
        • 3D Models
      • Editing Data
      • Solution Settings
      • Settings
      • Data Concepts
      • User Roles
      • Route Network
        • Barrier Route Element
        • Door Route Element
      • Additional Location Details
    • Map Template
      • Getting Started
        • Web Component
        • React Component
      • Configuration
        • Query Parameters
        • Categories
      • Customization
      • Deploying Map Template to a cloud storage provider
      • 2D/3D Visibility Switch
      • External customization of the Map Template
      • Location Details configuration
      • Kiosk
        • QR code configuration
  • Other
    • Map Design
      • Map Design System
      • Using a Custom Mapbox MapStyle
      • 2D Models
    • Changelog
      • Web SDK
        • V4
        • V3
      • Android SDK
        • V4
        • V3
      • iOS SDK
        • V4
        • V3
      • React Native SDK
      • Flutter SDK
      • MI Components
      • Map Template
    • Glossary
  • Legacy Docs
    • Android SDK V3
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
    • iOS SDK V3
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Directions
        • Live Data
        • Integrating MapsIndoors into your own App
      • Inspect Route Element for iOS v3
      • Using Cisco DNA Spaces
      • Using Indoor Atlas
      • Switching Solutions
      • Show User's Location aka. Blue Dot
      • Application User Roles
      • Getting a Polygon from a Location
      • Location Details
  • MapsIndoors SDK Firewall
  • Google Analytics & Logging
  • Reference Docs
    • Web SDK
    • Android SDK
    • iOS SDK
    • React Native SDK
    • Flutter SDK
Powered by GitBook
On this page
  • Show a List of Search Results​
  • Filter Locations on Map Based on Search Results​

Was this helpful?

Export as PDF
  1. SDKS & Frameworks
  2. Flutter
  3. Getting Started

Create a Search Experience

Last updated 24 days ago

Was this helpful?

Now you have simple app showing a map. In this step, you'll create a simple search and display the search results in a list. You'll also learn how to filter the data displayed on the map based on the search results.

Create a Simple Query Search

Start by creating a new Widget to facilitate searches on your application. Here we will be using a SearchWidget for searching with, while using a Drawer to display the results. We also create a search input field on our Scaffold for the user to input the text they want to search for. This is already setup in the basic example app.

To perform a search you will need to have initiated . This was shown in the previous section of the getting started tutorial how you do this.

For advanced usage of the search functionality read the Search guide and tutorials connected to it: , the examples are given for Android and iOS but the parameters and methods are the same in Flutter.

Show a List of Search Results

Create a search method that takes a search string as a parameter in your State class. In this example we only use the to limit our result to 30 locations. We will expand on this method later.

void search(String value) {
  // we should not search when the searchbar is empty
  if (value.isEmpty) {
    return;
  }
  // make a query with the search text
  MPQuery query = (MPQueryBuilder()..setQuery(value)).build();
  // we just want to see the top 30 results, as not to be overwhelmed
  MPFilter filter = (MPFilterBuilder()..setTake(30)).build();

  // fetch all (max 30) locations that match the query
  getLocationsByQuery(query: query, filter: filter).then((locations) {
    if (locations != null && locations.isNotEmpty) {
      // add UI handling here
    }
  }).catchError((err) {
    // handle the error, for now just show a snackbar
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
      content: Text("Search failed: $err"),
      backgroundColor: Colors.red,
    ));
  });
}

Next we create our own Widget to act as our search bar, this widget will take a function onSubmitted as a parameter, this is the function we will use to do the searcing when the user submits their search text.

class SearchWidget extends StatelessWidget {
  final Function(String val)? onSubmitted;
  const SearchWidget({
    super.key,
    this.onSubmitted,
  });

  @override
  Widget build(BuildContext context) {
    return TextField(
      decoration: const InputDecoration(
          icon: Icon(
            Icons.search,
            color: Colors.white,
          ),
          hintText: "Search...",
          hintStyle: TextStyle(color: Colors.white)),
      cursorColor: Colors.white,
      style: const TextStyle(color: Colors.white),
      onSubmitted: onSubmitted,
    );
  }
}

To be able to search we will use a text input field where a user can write what they want to search for. We can change the AppBar in our Scaffold to be the SearchWidget that we created earlier.

Now, when the user submits their text in the SearchWidget it will call the search function which we created earlier.

@override
Widget build(BuildContext context) {
  return Scaffold(
    ...
    appBar: AppBar(
      // we change the titlebar into a searching widget
      title: SearchWidget(
        onSubmitted: search,
      ),
    ),
    ...
  );
}

We now need some UI that can show the result of our search, for this we will use a Drawer which we can attach to our Scaffold. As the drawer is built directly in the build tree we can use a shared variable _searchResults which we will populate when a search is performed.

List<MPLocation> _searchResults = [];

@override
Widget build(BuildContext context) {
  return Scaffold(
    ...
    drawer: Drawer(
      child: Flex(
        direction: Axis.vertical,
        children: [
          Expanded(
            child: _searchResults.isNotEmpty
            ? ListView.builder(
                itemBuilder: (ctx, i) {
                  return ListTile(
                    onTap: () {
                      // when clicking on a location in the search results we will close the drawer and open a bottom sheet with that locations details
                      _mapControl.selectLocation(_searchResults[i]);
                      _scaffoldKey.currentState?.closeDrawer();
                    },
                    title: Text(_searchResults[i].name),
                  );
                },
                itemCount: _searchResults.length,
              )
            :
            // show something if the search returned no results
            const Icon(
              Icons.search_off,
              color: Colors.black,
              size: 100.0,
            ),
          ),
        ],
      ),
    ),
    ...
  );
}

Now that we have implemented the Drawer UI. Now we can add its activation to the search query method. We do this by putting the locations returned from our search into the _searchResults variable and then opening the Drawer from our Scaffold.

void search(String value) {
  ...
  // fetch all (max 30) locations that match the query
  getLocationsByQuery(query: query, filter: filter).then((locations) {
    if (locations != null && locations.isNotEmpty) {
      // show search results drawer
      setState(() {
        _searchResults = locations;
        _scaffoldKey.currentState?.openDrawer();
      });
      ...
    }
  }).catchError((err) {
    ...
  });
}

The standard implementation animates the camera to fit all Locations on the map and show the info window of a Location, if it's a list of only one Location.

  void search(String value) {
    // we should clear the search filter when the query is empty
    if (value.isEmpty) {
      _mapControl.clearFilter();
      setState(() {
        _searchResults = [];
      });
    }
    ...
    getLocationsByQuery(query: query, filter: filter).then((locations) {
      if (locations != null && locations.isNotEmpty) {
        ...
        // filter the map to only show matches
        _mapControl.setFilterWithLocations(locations, MPFilterBehavior.DEFAULT);
      }
    }).catchError((err) {
      ...
    });
  }

Expected result:

See the full example of the search method here:

Filter Locations on Map Based on Search Results

When getting a search result, you might want to only show those search results on the map. You can do this through . This method has different parameters to make it easier for you as a developer to fit your exact need in terms of animation and more.

When you are done showing the search results you can .

The accompanying UI and implementation of this search experience can be found in the getting started app sample.

​
MapsIndoors
Search Guide
​
setTake on the MPFilter
main.dart
​
calling setFilterWithLocations on MapsIndoorsWidget
call clearFliter
Getting Started App sample