首页 > 解决方案 > Flutter中的Google Maps Place Picker包错误

问题描述

当我尝试google_maps_place_picker在颤振中运行以下带有包的代码时,我得到了一个巨大的错误列表。

import 'package:flutter/material.dart';
// import 'package:google_maps/google_maps.dart';
import 'package:google_maps/google_maps.dart';
import 'package:google_maps_place_picker/google_maps_place_picker.dart'
    as place;
// import 'package:location/location.dart';

import '../components/location_helper.dart';
// import '../components/location_helper.dart';

class MapScreen extends StatelessWidget {
  final LatLng location1 = LatLng(37.657, -122.776);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Map Screen'),
        ),
        body: Center(
          child: place.PlacePicker(
              apiKey: GOOGLE_API,
              useCurrentLocation: true,
              onPlacePicked: (result) {
                print(result.addressComponents);
                Navigator.of(context).pop();
              }),
        ));
  }
}

错误

5:8:错误:未找到:“dart:html”导入“dart:html”显示文档、元素、节点;

错误:未找到:“dart:js”导出“dart:js”显示allowInterop、allowInteropCaptureThis;

错误:未找到:“dart:js_util”导出“dart:js_util”;

错误:找不到类型“元素”。元素mapDiv,[^^^^^^^

错误:找不到类型“节点”。List<MVCArray> 获取控件 => ^^^^

错误:找不到类型“元素”。元素 _getDiv() => callMethod(this, 'getDiv', []); ^^^^^^^

这些只是我提出的一些错误。还有很多这样的。

我在 pubspec.yaml 文件中添加了这些依赖项。

  google_maps_flutter: ^1.2.0
  geodesy: ^0.3.2
  confirm_dialog: ^0.1.1
  geocoding: ^1.0.5
  geocoder: ^0.2.1
  google_maps_place_picker: ^1.0.1
  tuple: ^1.0.3
  js: ^0.6.2
  html: ^0.14.0+4

标签: fluttergoogle-mapsdartgoogle-place-picker

解决方案


您正在使用import 'package:google_maps/google_maps.dart';

google_maps 包只支持 web。对于移动支持应该试用flutter_google_placesgoogle_maps_flutter或任何其他包。


推荐阅读