title: NoSuchMethodError The method '[]' was called on null
body: <p>I have been developing an app like uber, and I'm facing this problem when I choose one of autocomplete addresses list in the destination search bar.</p>
  <p>Here are my main screen codes:</p>
  <pre><code>import 'dart:async';
  import 'package:flutter_polyline_points/flutter_polyline_points.dart';
  import 'package:geolocator/geolocator.dart';
  import 'package:flutter/cupertino.dart';
  import &quot;package:flutter/material.dart&quot;;
  import 'package:google_maps_flutter/google_maps_flutter.dart';
  import 'package:provider/provider.dart';
  import 'package:topride/AllScreens/searchScreen.dart';
  import 'package:topride/AllWidgets/Divider.dart';
  import 'package:topride/Assistants/AssistantMethods.dart';
  import 'package:topride/DataHandler/appData.dart';
  import 'package:topride/AllWidgets/progressDialog.dart';
  
  class MainScreen extends StatefulWidget {
  
    static const String idScreen = &quot;mainScreen&quot;;
  
    const MainScreen({Key key}) : super(key: key);
  
    @override
    _MainScreenState createState() =&gt; _MainScreenState();
  }
  
  
  class _MainScreenState extends State&lt;MainScreen&gt; {
  
    Completer&lt;GoogleMapController&gt; _controllerGoogleMap = Completer();
  
     GoogleMapController newgoogleMapController ;
  
    GlobalKey&lt;ScaffoldState&gt; scaffoldKey=new GlobalKey&lt;ScaffoldState&gt;();
  
    List&lt;LatLng&gt; pLineCoordinates=[];
    Set&lt;Polyline&gt;polyLineSet ={};
  
  
     Position currentPosition;
    var geoLocator = Geolocator();
    double bottomPaddingOfMap = 0;
  
    Set&lt;Marker&gt; markersSet = {};
    Set&lt;Circle&gt; circlesSet = {};
  
  
  
    void locatePosition()async{
      Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.bestForNavigation);
      currentPosition=position;
      LatLng latLngPosition = LatLng(position.latitude, position.longitude);
      CameraPosition cameraPosition = new CameraPosition(target: latLngPosition,zoom: 14);
      newgoogleMapController.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
  
      String address=await AssistantMethods.searchCoordinateAddress(position,context);
      print(&quot;This is Your Address ::&quot;+ address);
  
  
    }
  
  
    static final CameraPosition _kGooglePlex = CameraPosition(
      target: LatLng(37.42796133580664, -122.085749655962),
      zoom: 14.4746,
    );
  
  
    @override
  
  
  
    Widget build(BuildContext context) {
      return Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: Text(&quot;Maine Screen&quot;),
        ),
  
        drawer: Container(
          color: Colors.white,
          width: 255.0,
          child: Drawer(
            child: ListView(
              children: [
                //drawer header
                Container(
                  height: 165.0,
                  child: DrawerHeader(
                    decoration: BoxDecoration(color: Colors.white),
                    child: Row(
                      children: [
                        Image.asset(&quot;images/user_icon.png&quot;,
                        height: 65.0,width: 65.0,
                        ),
                        SizedBox(width: 16.0),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(&quot;Profile Name&quot;, style: TextStyle(fontSize: 16.0,fontFamily: &quot;Brand Bolt&quot;),),
  
                            SizedBox(height: 6.0,),
                            Text(&quot;View Profile&quot;),
  
                          ],
                        ),
  
                      ],
                    ),
                  ),
                ),
  
                DividerWidget(),
                SizedBox(height: 12.0,),
                //drawer Body Button
                ListTile(
                  leading: Icon(Icons.history),
                  title: Text(&quot;History&quot;,style: TextStyle(fontSize: 15.0),),
                ),
                ListTile(
                  leading: Icon(Icons.person),
                  title: Text(&quot;View Profile&quot;,style: TextStyle(fontSize: 15.0),),
                ),
                ListTile(
                  leading: Icon(Icons.info),
                  title: Text(&quot;About&quot;,style: TextStyle(fontSize: 15.0),),
                ),
  
  
              ],
            ),
          ),
        ),
  
        body: Stack(
          children: [
            GoogleMap(
              padding: EdgeInsets.only(bottom: bottomPaddingOfMap),
              mapType: MapType.normal,
              myLocationButtonEnabled: true,
              initialCameraPosition: _kGooglePlex,
  
              myLocationEnabled: true,
              zoomGesturesEnabled: true,
              zoomControlsEnabled: true,
              polylines: polyLineSet,
              markers: markersSet,
              circles: circlesSet,
  
              onMapCreated: (GoogleMapController controller){
  
         _controllerGoogleMap.complete(controller);
         newgoogleMapController = controller;
         locatePosition();
  
         setState(() {
           bottomPaddingOfMap=300.0;
         });
  
  
  
              },
            ),
  
            // Hamburger Button fo drawer
            Positioned(
              top: 25.0,
              left: 22.0,
              child: GestureDetector(
                onTap: (){
               scaffoldKey.currentState.openDrawer();
  
                },
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(22.0),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black,
                        blurRadius: 6.0,
                        spreadRadius: 0.5,
                        offset: Offset(0.7,0.7),
                      ),
                    ],
  
                  ),
                  child: CircleAvatar(
                    backgroundColor: Colors.white,
                    child: Icon(Icons.menu, color: Colors.black,),
                    radius: 20.0,
  
                  ),
  
                ),
              ),
            ) ,
            Positioned(
              left: 0.00,
              right: 0.00,
              bottom: 0.00,
              child: Container(
                height: 300.0,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(topLeft: Radius.circular(18.0),topRight: Radius.circular(15.0)),
                  boxShadow: [BoxShadow(
                    color: Colors.black,
                    blurRadius: 16.0,
                    spreadRadius: 0.5,
                    offset: Offset(0.7,0.7),
  
                  ),],
  
                ),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 6.0),
                      Text(&quot;Hi there,&quot;,style: TextStyle(fontSize:  10.0),),
                      Text(&quot;Where to ?,&quot;,style: TextStyle(fontSize:  20.0, fontFamily: &quot;Brand Bolt&quot;),),
                      SizedBox(height: 20.0),
  
                      
                      GestureDetector(
  
                        onTap: ()async{
                          var res = await Navigator.push(context, MaterialPageRoute(builder: (context)=&gt;SearchScreen()));
                          if (res==&quot;obtainDirection&quot;){
  
                            await getPlaceDirection();
                          }
                        },
  
                        child: Container(
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(5.0),
                            boxShadow: [BoxShadow(
                              color: Colors.black54,
                              blurRadius: 6.0,
                              spreadRadius: 0.5,
                              offset: Offset(0.7,0.7),
  
                            ),],
  
                          ),
                          child: Padding(
                            padding: const EdgeInsets.all(12.0),
                            child: Row(
                              children: [
                                Icon(Icons.search,color: Colors.blue,),
                                SizedBox(width: 10.0,),
                                Text(&quot;Search Drop off&quot;),
                              ],),
                          ),
                        ),
                      ),
                      SizedBox(height: 24.0),
                      Row(
                        children: [
                          Icon(Icons.home,color: Colors.grey,),
                          SizedBox(width: 12.0),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                Provider.of&lt;AppData&gt;(context).pickUpLocation != null ?
                                      Provider.of&lt;AppData&gt;(context).pickUpLocation.placeName:
                                    &quot;Add Home&quot;
                              ),
                              SizedBox(height: 10.0),
                              Text(&quot;Your Living Home Address&quot;,style: TextStyle(color: Colors.black54,
                              fontSize: 12.0),),
  
                            ],
                          ),
  
                        ],
                      ),
  
                      SizedBox(height: 10.0),
                      DividerWidget(),
                      SizedBox(height: 16.0),
  
                      Row(
                        children: [
                          Icon(Icons.work,color: Colors.grey,),
                          SizedBox(width: 12.0),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(&quot;Add Work&quot;),
                              SizedBox(height: 10.0),
                              Text(&quot;Your Office Address&quot;,style: TextStyle(color: Colors.black54,
                                  fontSize: 12.0),),
  
                            ],
                          ),
  
                        ],
                      ),
  
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
  
      );
  
    }
    Future&lt;void&gt; getPlaceDirection() async{
      var initialPos =Provider.of&lt;AppData&gt;(context,listen: false).pickUpLocation;
      var finalPos =Provider.of&lt;AppData&gt;(context,listen: false).dropOffLocation;
  
      var pickUpLatLng = LatLng(initialPos.latitude, initialPos.longitude);
      var dropOffLatLng = LatLng(finalPos.latitude, finalPos.longitude);
  
      showDialog(context: context,
  
          builder: (BuildContext context)=&gt; ProgressDialog (message:&quot;please wait...&quot;)
      );
      var details = await AssistantMethods.obtainPlaceDirectionDetails(pickUpLatLng, dropOffLatLng);
  
      Navigator.pop(context);
  
      print(&quot;This is Encoding Points :: &quot;);
      print(details.encodingPoints);
      PolylinePoints polylinePoints=PolylinePoints();
      List&lt;PointLatLng&gt; decodedPolyLinePointsResult = polylinePoints.decodePolyline(details.encodingPoints);
  
      pLineCoordinates.clear();
  
      if(decodedPolyLinePointsResult.isNotEmpty){
        decodedPolyLinePointsResult.forEach((PointLatLng pointLatLng) {
  
          pLineCoordinates.add(LatLng(pointLatLng.latitude,pointLatLng.longitude));
        });
      }
      polyLineSet.clear();
  
      setState(() {
        Polyline polyline = Polyline(
          color: Colors.pink,
          polylineId: PolylineId(&quot;PolylineID&quot;),
          jointType: JointType.round,
          points: pLineCoordinates,
          width: 5,
          startCap: Cap.roundCap,endCap: Cap.roundCap,
          geodesic: true,
        );
        polyLineSet.add(polyline);
  
      });
  
      LatLngBounds latLngBounds;
      if(pickUpLatLng.latitude&gt;dropOffLatLng.latitude &amp;&amp; pickUpLatLng.longitude&gt;dropOffLatLng.longitude){
        latLngBounds=LatLngBounds(southwest: dropOffLatLng, northeast: pickUpLatLng);
      }
      else if(pickUpLatLng.longitude&gt;dropOffLatLng.longitude ){
        latLngBounds=LatLngBounds(southwest: LatLng(pickUpLatLng.latitude,dropOffLatLng.longitude),
            northeast:  LatLng(dropOffLatLng.latitude,pickUpLatLng.longitude));
      }
  
      else if(pickUpLatLng.latitude&gt;dropOffLatLng.latitude ){
        latLngBounds=LatLngBounds(southwest: LatLng(dropOffLatLng.latitude,pickUpLatLng.longitude),
            northeast:  LatLng(pickUpLatLng.latitude,dropOffLatLng.longitude));
    }
      else {
        latLngBounds =LatLngBounds(southwest: pickUpLatLng, northeast: dropOffLatLng);
      }
      newgoogleMapController.animateCamera(CameraUpdate.newLatLngBounds(latLngBounds, 70));
      Marker pickUpLocationMarker= Marker(
        icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed),
        infoWindow: InfoWindow(title: initialPos.placeName,snippet: &quot;my location&quot;),
        position: pickUpLatLng,
        markerId: MarkerId(&quot;pickUpId&quot;),
      );
  
      Marker dropOffLocationMarker= Marker(
        icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueGreen),
        infoWindow: InfoWindow(title: finalPos.placeName,snippet: &quot;DropOff Location&quot;),
        position: dropOffLatLng,
        markerId: MarkerId(&quot;dropOffId&quot;),
      );
      setState(() {
        markersSet.add(pickUpLocationMarker);
        markersSet.add(dropOffLocationMarker);
      });
  
      Circle pickUpLocCircle = Circle(
        fillColor: Colors.red,
        center: pickUpLatLng,
        radius: 12,
        strokeWidth: 4,
        strokeColor: Colors.redAccent,
        circleId: CircleId(&quot;pickUpId&quot;),
      );
      Circle dropOffLocCircle = Circle(
        fillColor: Colors.green,
        center: pickUpLatLng,
        radius: 12,
        strokeWidth: 4,
        strokeColor: Colors.greenAccent,
        circleId: CircleId(&quot;dropOffId&quot;),
      );
      setState(() {
        circlesSet.add(pickUpLocCircle);
        circlesSet.add(dropOffLocCircle);
      });
  
      }
  }
  </code></pre>
  <p>Search Screen:</p>
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  import 'package:provider/provider.dart';
  import 'package:topride/AllWidgets/Divider.dart';
  import 'package:topride/Assistants/requestAssistant.dart';
  import 'package:topride/DataHandler/appData.dart';
  import 'package:topride/Models/address.dart';
  import 'package:topride/Models/placePredictions.dart';
  import 'package:topride/configMaps.dart';
  import 'package:topride/AllWidgets/progressDialog.dart';
  
  
  class SearchScreen extends StatefulWidget {
    const SearchScreen({Key key}) : super(key: key);
  
    @override
    _SearchScreenState createState() =&gt; _SearchScreenState();
  }
  
  class _SearchScreenState extends State&lt;SearchScreen&gt; {
  
    TextEditingController pickUpTextEditingController= TextEditingController();
    TextEditingController dropOffTextEditingController= TextEditingController();
    List&lt;PlacePredictions&gt; placePredictionList = [];
  
    @override
    Widget build(BuildContext context) {
  
      String placeAddress= Provider.of&lt;AppData&gt;(context).pickUpLocation?.placeName ?? &quot;&quot;;
          pickUpTextEditingController.text =placeAddress;
  
      return Scaffold(
        body: Column(
          children: [
            Container(
              height: 215.0,
              decoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    color: Colors.black,
                    blurRadius: 6.0,
                    spreadRadius: 0.5,
                    offset: Offset(0.7,0.7),
                  ),
                ],
              ),
              child: Padding(
                padding: EdgeInsets.only(left: 25.0,top: 25.0, right: 25.0,bottom: 20.0),
                child: Column(
                  children: [
                    SizedBox(height: 5.0),
                    Stack(
                      children: [
                        
                        GestureDetector(
                          onTap: (){
                            Navigator.pop(context);
                          },
                          child: Icon(
                              Icons.arrow_back),
                        ),
                        
                        Center(
                          child: Text(&quot;Set Drop Off&quot;,style: TextStyle(fontSize: 18.0,fontFamily: &quot;Brand Bolt&quot;),),
  
                        ),
                      ],
                    ),
                    SizedBox(height: 16.0),
                    Row(
                      children: [
                        Image.asset(&quot;images/pickicon.png&quot;,height: 16.0,width: 16.0,),
                        SizedBox(width: 18.0),
                        Expanded(
                            child: Container(
                              decoration: BoxDecoration(
                                color: Colors.grey[400],
                                borderRadius: BorderRadius.circular(5.0),
                              ),
                              child: Padding(
                                padding: EdgeInsets.all(3.0),
                                child: TextField(
                                  controller: pickUpTextEditingController,
                                  decoration:InputDecoration(
                                    hintText: &quot;PickUp Location&quot;,
                                    fillColor: Colors.grey[400],
                                    filled: true,
                                    border: InputBorder.none,
                                    isDense: true,
                                    contentPadding: EdgeInsets.only(left: 11.0,top: 8.0,bottom: 8.0,),
                                  ) ,
                                ),
                              ),
                            ),
                        ),
                      ],
                    ),
  
                    SizedBox(height: 10.0),
                    Row(
                      children: [
                        Image.asset(&quot;images/desticon.png&quot;,height: 16.0,width: 16.0,),
                        SizedBox(width: 18.0),
                        Expanded(
                          child: Container(
                            decoration: BoxDecoration(
                              color: Colors.grey[400],
                              borderRadius: BorderRadius.circular(5.0),
                            ),
                            child: Padding(
                              padding: EdgeInsets.all(3.0),
                              child: TextField(
  
                                onChanged: (val){
                                  findPlace(val);
                                },
                                controller: dropOffTextEditingController,
                                decoration:InputDecoration(
                                  hintText: &quot;Destination&quot;,
                                  fillColor: Colors.grey[400],
                                  filled: true,
                                  border: InputBorder.none,
                                  isDense: true,
                                  contentPadding: EdgeInsets.only(left: 11.0,top: 8.0,bottom: 8.0,),
                                ) ,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
  
                  ],
                ),
               ),
            ),
  
            // tile for predictions
  
            (placePredictionList.length&gt;0)? Padding(
              padding: EdgeInsets.symmetric(vertical: 8.0,horizontal: 16.0),
              child: ListView.separated(
                padding: EdgeInsets.all(0.0),
                itemBuilder: (context,index){
                  return PredictionTile(placePredictions: placePredictionList[index]);
  
                },
                separatorBuilder: (BuildContext context , int index)=&gt; DividerWidget(),
                itemCount: placePredictionList.length,
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
              ),
            ) : Container()
          ],
        ),
      );
    }
    void findPlace(String placeName)async{
      if (placeName.length&gt;1){
        String autoCompleteUrl =&quot;https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$placeName&amp;key=$mapkey&amp;sessiontoken=1234567890&amp;components=country:us&quot;;
  
        var res = await RequestAssistant.getRequest(autoCompleteUrl);
        if (res == &quot;failed&quot;){
          return ;
        }
       if(res[&quot;status&quot;]==&quot;OK&quot;){
         var predictions=res[&quot;predictions&quot;];
         var placesList = (predictions as List).map((e) =&gt; PlacePredictions.fromJson(e)).toList();
  
         setState(() {
           placePredictionList = placesList ;
         });
       }
      }
    }
  }
  
  
  class PredictionTile extends StatelessWidget {
  
    final PlacePredictions placePredictions;
  
     PredictionTile({Key key,this.placePredictions}) : super(key: key);
  
  
  
    @override
    Widget build(BuildContext context) {
      
      return TextButton(
  
        onPressed: (){
          gtPlaceAddressDetails(placePredictions.place_id,context);
        },
        child: Container(
          child: Column(
  
           children: [
             SizedBox(width: 10.0,),
              Row(
               children: [
                 Icon(Icons.add_location),
                 SizedBox(width: 14.0,),
                 Expanded(
                   child: Column(
                     crossAxisAlignment: CrossAxisAlignment.start,
                     children: [
                       Text(placePredictions.main_text,overflow: TextOverflow.ellipsis ,style: TextStyle(fontSize: 16.0),),
                       SizedBox(height: 3.0,),
                       Text(placePredictions.secondary_text,overflow: TextOverflow.ellipsis ,style: TextStyle(fontSize: 12.0,color: Colors.grey),),
  
                     ],
                   ),
                 ),
               ],
             ),
             SizedBox(width: 10.0,),
           ],
          ),
        ),
      );
    }
  
  
    void gtPlaceAddressDetails (String placeId,context)async{
      showDialog(context: context,
  
          builder: (BuildContext context)=&gt; ProgressDialog (message:&quot;Setting Drop Off ,please wait&quot;)
      );
  
  
      String placeDetailsUrl = &quot;https://maps.googleapis.com/maps/api/place/details/json?place_id=$placeId&amp;key=$mapkey&quot;;
      var res = await RequestAssistant.getRequest(placeDetailsUrl);
  
      Navigator.pop(context);
  
      if(res==&quot;failed&quot;){
        return;
  
      }
      if(res[&quot;status&quot;]==&quot;OK&quot;){
        Address address= Address();
        address.placeName=res[&quot;result&quot;][&quot;name&quot;];
        address.placeId=placeId;
        address.latitude=res[&quot;result&quot;][&quot;geometry&quot;][&quot;location&quot;][&quot;lat&quot;];
        address.longitude=res[&quot;result&quot;][&quot;geometry&quot;][&quot;location&quot;][&quot;lng&quot;];
  
        Provider.of &lt;AppData&gt; (context,listen: false).updateDropOffLocationAddress(address);
  
        print(&quot;This is Drop Off Location :: &quot;);
        print(address.placeName);
        Navigator.pop(context, &quot;obtainDirection&quot;);
      }
    }
  }
  </code></pre>
  <p>Flutter Run:</p>
  <pre><code>I/flutter ( 9764): This is Drop Off Location :: 
  I/flutter ( 9764): Santa Clara
  E/flutter ( 9764): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
  E/flutter ( 9764): Receiver: null
  E/flutter ( 9764): Tried calling: [](0)
  E/flutter ( 9764): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
  E/flutter ( 9764): #1      AssistantMethods.obtainPlaceDirectionDetails (package:topride/Assistants/AssistantMethods.dart:51:49)
  E/flutter ( 9764): &lt;asynchronous suspension&gt;
  E/flutter ( 9764): #2      _MainScreenState.getPlaceDirection (package:topride/AllScreens/MainScreen.dart:323:19)
  E/flutter ( 9764): &lt;asynchronous suspension&gt;
  E/flutter ( 9764): #3      _MainScreenState.build.&lt;anonymous closure&gt; (package:topride/AllScreens/MainScreen.dart:229:27)
  E/flutter ( 9764): &lt;asynchronous suspension&gt;
  E/flutter ( 9764): 
  I/Alqasim.TopRid( 9764): Waiting for a blocking GC ProfileSaver
  I/Alqasim.TopRid( 9764): WaitForGcToComplete blocked ProfileSaver on HeapTrim for 7.337ms
  I/Alqasim.TopRid( 9764): Waiting for a blocking GC ProfileSaver
  I/Alqasim.TopRid( 9764): WaitForGcToComplete blocked ProfileSaver on HeapTrim for 19.440ms
  I/Alqasim.TopRid( 9764): Background young concurrent copying GC freed 69538(2560KB) AllocSpace objects, 0(0B) LOS objects, 26% free, 7194KB/9816KB, paused 5.012ms total 28.771ms
  I/Alqasim.TopRid( 9764): WaitForGcToComplete blocked HeapTrim on None for 6.576ms
  I/Alqasim.TopRid( 9764): Background concurrent copying GC freed 84239(3130KB) AllocSpace objects, 17(1132KB) LOS objects, 49% free, 5486KB/10MB, paused 938us total 133.120ms
   
  </code></pre>
  <p>It shows no error when I'm coding but when I run the app it comes with this error when I choose an address and no encoded points in return.</p>