【问题标题】:flutter google places: Unhandled Exception: Null check operator used on a null value颤振谷歌地方:未处理的异常:空值检查运算符用于空值
【发布时间】:2021-05-24 03:07:24
【问题描述】:

我正在使用google mapgoogle places 开发一个应用程序。

当我调用PlacesAutocomplete.show() 时,它会给出以下错误消息。 Null check operator used on a null value

  • pubspec.yaml

    environment:
       sdk: ">=2.7.0 <3.0.0"
    
    dependencies:
       google_maps_flutter: ^2.0.5
       flutter_polyline_points: ^1.0.0
       location: ^4.1.1  
       flutter_google_places: ^0.3.0
    
  • 打电话

    InkWell(
       onTap: () async {
           Prediction p = await PlacesAutocomplete.show(
              context: context,
              apiKey: GOOGLE_API_KEY,
           );
        }, child: Text("SHOW") 
    ),
    

提前致谢。

【问题讨论】:

  • 能否请您提供Minimal, Reproducible Example 以便我们看看可能导致问题的原因?
  • 我刚刚添加了 InkWell 以显示自动完成屏幕。
  • typescomponentsstrictbounds 为必填项

标签: flutter google-maps dart


【解决方案1】:

您需要提供函数 .show 的所有必需参数和非 null 参数。类似的东西:

Prediction p = await PlacesAutocomplete.show(
      offset: 0,
      radius: 1000,
      strictbounds: false,
      region: "us",
      language: "en",
      context: context,
      mode: Mode.overlay,
      apiKey: Env.googleapikey,
      sessionToken: sessionToken,
      components: [new Component(Component.country, "us")],
      types: ["(cities)"],
      hint: "Search City",
      startText: city == null || city == "" ? "" : city
    );

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2021-07-22
    • 2021-08-19
    • 1970-01-01
    • 2021-07-08
    • 2021-11-21
    • 2021-11-21
    • 2022-07-20
    相关资源
    最近更新 更多