提问者:小点点

flutter错误:用于搜索google位置位置的空值上的空检查运算符


这是我搜索谷歌位置的代码,但我得到了错误空检查运算符用于搜索谷歌位置的空值。

这是我搜索谷歌位置位置的代码,但我在搜索谷歌位置位置的空值上使用了错误空检查运算符。如何解决它。

import 'package:flutter/material.dart';
import 'package:flutter_geocoder/geocoder.dart';
import 'dart:async';
import 'dart:math';


import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_maps_webservice/places.dart';
void main() => runApp(MyApp());

const kGoogleApiKey = "Your key";

GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: demo(),
      ),
    );
  }
}

class demo extends StatefulWidget {
  @override
  demoState createState() => new demoState();
}

class demoState extends State<demo> {
  @override
  Widget build(BuildContext context) {

    return Scaffold(
        body: Container(
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () async {
                // show input autocomplete with selected mode
                // then get the Prediction selected
                // Prediction? p = await PlacesAutocomplete.show(
                //     context: context, apiKey: kGoogleApiKey);
                // displayPrediction(p!);
                Prediction? p = await PlacesAutocomplete.show(
                    context: context,
                    apiKey: kGoogleApiKey,
                    // mode: Mode.overlay, // Mode.fullscreen
                     );
                print(p);

              },
              child: Text('Find address'),

            )
        )
    );
  }

  Future<Null> displayPrediction(Prediction p) async {

    if (p != null) {
      PlacesDetailsResponse detail =
      await _places.getDetailsByPlaceId(p.placeId.toString());

      var placeId = p.placeId;
      double lat = detail.result.geometry!.location.lat;
      double lng = detail.result.geometry!.location.lng;

      var address = await Geocoder.local.findAddressesFromQuery(p.description.toString());
print(address);
      print(lat);
      print(lng);
    }
  }
}


共1个答案

匿名用户

它的意思是详细信息。结果。几何返回null,因此使用null检查运算符又名在其上输出错误。