Flutter Maps 实时位置崩溃,因为实时位置不是 Future<dynamic> 你如何解决?

Flutter Maps live location crashes because live location is not a Future<dynamic> how do you fix?

我开始从事一个 flutter 项目,我必须使用 google 地图和一个人的实时位置才能将他们带到某个地方。我在屏幕上看到了 google 个地图,但是当我开始添加实时位置时它崩溃了。我也有一个带有标准位置的屏幕,但由于实时位置导致此屏幕崩溃 crashes/closes 整个应用程序。

在实时位置屏幕上,我现在看到一个红色屏幕:'Future 不是 'CameraPosition' 类型的子类型。我在 visualstudio 代码上也有这个错误:无法打开 'libobject_patch.dart':无法读取未定义的 属性 'create'。

我使用 google 地图和位置相关性。

我试过使用 try on,但它获取了位置(用断点检查),但它没有 return 正确的数据(它 return 是未来)

这是我在 类 中使用的代码。有点乱,这是我的第一个flutter项目

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';


//deze functie werkt, hij vindt de locatie als al is toegestaan
//ook wordt er gevraagd om de locatie als deze nog niet is gegeven
//daarna pas de error
  GoogleMapController myController;
  Location location = new Location();
  _animateToUser() async{
    location.onLocationChanged();
    try{
      LocationData pos = await location.getLocation();
        myController.animateCamera(CameraUpdate.newCameraPosition(
          CameraPosition(
            target: LatLng(pos.latitude, pos.longitude),
            zoom: 12.0,
          )
        )
      );
    }
    on Exception{
      final CameraPosition pos = CameraPosition(
      target: LatLng(52.0575, 4.49306),
      zoom: 12.0,
      );
    }
  }

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
    GoogleMapController myController;
    Location location = new Location();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
      title: new Text("P-App"),
      ),
      backgroundColor: Colors.lightBlueAccent,
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ButtonTheme(
              minWidth: 200.0,
              height: 10.0,
              child: RaisedButton(
                  onPressed: (){
                    _animateToUser();                    
                    Navigator.push(context,
                    MaterialPageRoute(builder: (context) => VindLocatie()),
                    );
                  //invoeren naar de pagina met maps waar gebruiker om locatie wordt gevraagd
                  },
                  elevation: 5.0,
                  textColor: Colors.blue,
                  color: Colors.white,
                  padding: const EdgeInsets.all(8.0),
                  child: new Text(
                    "Zoek met uw locatie",
                  ),
            ),
            ),
            ButtonTheme(
              minWidth: 200.0,
              height: 10.0,
              child: RaisedButton(
                onPressed: (){
                  Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => EigenLocatie()),
                  );
                },
                elevation: 5.0,
                textColor: Colors.blue,
                color: Colors.white,
                padding: const EdgeInsets.all(8.0),
                  child: new Text(
                    "Zoek met opgegeven locatie",
                  ),
            ),
            ),
          ],
        )
        )
    );
  }
}

class VindLocatie extends StatelessWidget{

  GoogleMapController myController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("P-App"),
      ),
      body: Column(
        children: <Widget>[
          Container(
            height: 350.0, //Manier vinden om voor de helft te zetten ( misschien met percentages ofzo)
            width: MediaQuery.of(context).size.width,
            child:GoogleMap(
              mapType: MapType.hybrid,
              initialCameraPosition: _animateToUser(),
              onMapCreated: (GoogleMapController controller) {
                myController = controller;
              },
            ),
          ),
        ],
    ),
    );
  }
}

我需要用户的实时位置。 实际结果是红屏,future 不是 CameraPosition 的子类型。

现在有效,你必须改变未来。它与 await 语句一样。如果你想要更新的版本就问我,但我必须搜索它因为它已经有一段时间了