title: The method 'map' was called on null. Receiver: null Tried calling: map(Closure: (dynamic)
body: <p>I am getting the following error, how to sort it out?</p>
  <pre><code>════════ Exception caught by widgets library ═══════════════════════════════════
  The following NoSuchMethodError was thrown building SearchBar(dirty, state: _SearchBar#31f4e):
  The method 'map' was called on null.
  Receiver: null
  Tried calling: map(Closure: (dynamic) =&gt; SearchSuggestion)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/FvCXd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FvCXd.jpg" alt="enter image description here" /></a></p>
  <pre><code> import 'dart:convert';
   import 'package:flutter/material.dart';
   import 'package:http/http.dart' as http;
  
   import 'listview.dart';
  
   class SearchBar extends StatefulWidget {
     const SearchBar({Key key}) : super(key: key);
  
     @override
     State createState() {
       return _SearchBar();
     }
   }
  
   class _SearchBar extends State {
     bool searching, error;
  
     var data;
     String query;
     String dataurl = &quot;http://localhost/search.php&quot;;
  
     @override
     void initState() {
       searching = false;
       error = false;
       query = &quot;&quot;;
       super.initState();
     }
  
  
     navigateToNextActivity(BuildContext context, String dataHolder) {
       Navigator.of(context).push(MaterialPageRoute(
           builder: (context) =&gt; SecondScreenState(dataHolder.toString())));
     }
  
     void getSuggestion() async {
  
       var res = await http.post(dataurl + &quot;?query=&quot; + Uri.encodeComponent(query));
  
       if (res.statusCode == 200) {
         setState(() {
           data = json.decode(res.body);
      
         });
       } else {
    
         setState(() {
           error = true;
         });
       }
     }
  
     @override
     Widget build(BuildContext context) {
       return Scaffold(
           appBar: AppBar(
             leading: searching
                 ? IconButton(
                     icon: const Icon(Icons.arrow_back),
                     onPressed: () {
                       setState(() {
                         searching = false;
                    
                       });
                     },
                   )
                 : const Icon(Icons.play_arrow),
        
             title: searching ? searchField() : const Text(&quot;Search&quot;),
             actions: [
               IconButton(
                   icon: const Icon(Icons.search),
                   onPressed: () {
                     setState(() {
                       searching = true;
                     });
                   }), 
  
          
             ],
             backgroundColor: searching
                 ? const Color.fromARGB(255, 111, 70, 173)
                 : const Color.fromARGB(255, 111, 70, 173),
        
           ),
           body: SingleChildScrollView(
               child: Container(
                   alignment: Alignment.center,
                   child: data == null
                       ? Container(
                           padding: const EdgeInsets.all(20),
                           child: searching
                               ? const Text(&quot;Please wait&quot;)
                               : const Text(&quot;Search Job&quot;)
                      
                           )
                       : Container(
                           child: searching
                               ? showSearchSuggestions()
                               : const Text(&quot;No Data Found&quot;),
                         )
              
                   )));
     }
  
     Widget showSearchSuggestions() {
       List suggestionlist = List.from(data[&quot;data&quot;].map((i) {
         return SearchSuggestion.fromJSON(i);
       }));
  
       return Column(
         children: suggestionlist.map((suggestion) {
           return InkResponse(
               onTap: () {
         
  
                 navigateToNextActivity(context, suggestion.id);
               },
               child: SizedBox(
                   width: double.infinity, 
                   child: Card(
                     child: Container(
                       padding: const EdgeInsets.all(15),
                       child: Text(
                         suggestion.name,
                         style: const TextStyle(
                           fontSize: 20,
                           fontWeight: FontWeight.bold,
                         ),
                       ),
                     ),
                   )));
         }).toList(),
       );
     }
  
     Widget searchField() {
  
       return TextField(
         autofocus: true,
         style: const TextStyle(color: Colors.white, fontSize: 18),
         decoration: const InputDecoration(
           hintStyle: TextStyle(color: Colors.white, fontSize: 18),
           hintText: &quot;Search Job&quot;,
           enabledBorder: UnderlineInputBorder(
             borderSide: BorderSide(color: Colors.white, width: 2),
           ), 
           focusedBorder: UnderlineInputBorder(
             borderSide: BorderSide(color: Colors.white, width: 2),
           ), 
         ), 
         onChanged: (value) {
           query = value; 
           getSuggestion(); 
         },
       );
     }
   }
  
  
   class SearchSuggestion {
     String id, name;
     SearchSuggestion({this.id, this.name});
  
     factory SearchSuggestion.fromJSON(Map&lt;String, dynamic&gt; json) {
       return SearchSuggestion(
         id: json[&quot;id&quot;],
         name: json[&quot;name&quot;],
       );
     }
   }
  </code></pre>