【问题标题】:TypeError: Cannot read properties of undefined (reading 'maps') in flutterTypeError:无法在颤动中读取未定义的属性(读取\'maps\')
【发布时间】:2022-08-13 21:04:42
【问题描述】:

我正在开发一个超级克隆,但是当我在网络上运行应用程序时,它不会让我看到地图上的位置并且我得到这个错误,它有帮助!

在这里您还可以看到应用程序执行时的结果

    import \'dart:async\';
    import \'package:flutter/material.dart\';
    import \'package:geolocator/geolocator.dart\';
    import \'package:google_maps_flutter/google_maps_flutter.dart\';
    import \'package:rider_app/AllWidgets/Divider.dart\';
    import \'package:rider_app/Assistants/assistantsMethods.dart\';



    class MainScreen extends StatefulWidget
    {
      static const String idScreen = \"mainScreen\";
      @override
      _MainScreenState createState() => _MainScreenState();
    }



    class _MainScreenState extends State<MainScreen>
    {
      Completer<GoogleMapController> _controllerGoogleMaps = Completer();
      GoogleMapController newGoogleMapController;

      GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();

      Position currentPosition;
      var geoLocator = Geolocator();
      double bottomPaddingOfMap = 0;

      void locatePosition() async
      {
        Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
        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 AssistantsMethods.searchCoordinateAddress(position);
        print(\"Esta es tú dirección :: \" + 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(\"Ventana Principal\"),
          ),
          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(\"images/user_icon.png\", height: 65.0,width: 65.0,),
                          SizedBox(width: 16.0,),
                          Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(\"Nombre del perfil\", style: TextStyle(fontSize: 16.0, fontFamily: \"Brand-Bold\"),),
                              SizedBox(height: 6.0,), 
                              Text(\"Perfil Visitante\"),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                  DividerWidget(),

                  SizedBox(height: 12.0,),

                  //Drawer Body Controller
                  ListTile(
                    leading: Icon(Icons.history),
                    title: Text(\"Historia\", style: TextStyle(fontSize: 15.0),),
                  ),
                  ListTile(
                    leading: Icon(Icons.person),
                    title: Text(\"Perfil de visitante\", style: TextStyle(fontSize: 15.0),),
                  ),
                  ListTile(
                    leading: Icon(Icons.info),
                    title: Text(\"Sobre\", 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,
                onMapCreated: (GoogleMapController controller)
                {
                  _controllerGoogleMaps.complete(controller);
                  newGoogleMapController =  controller;

                  setState(() {
                    bottomPaddingOfMap = 300.0;
                  });

                  locatePosition();

                },
              ),

              Positioned(
                top: 45.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.0,
                right: 0.0,
                bottom: 0.0,
                child: Container(
                  height: 300.0,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(18.0), topRight: Radius.circular(18.0)),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black,
                        blurRadius: 16.0,
                        spreadRadius: 0.5,
                        offset: Offset(0.7, 0.7),
                      )
                    ],
                  ),
                  child: Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 18.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 6.0),
                        Text(\"Hola,Buen día..\", style: TextStyle(fontSize: 12.0),),
                        Text(\"A dondé quisieras ir?\", style: TextStyle(fontSize: 20.0, fontFamily: \"Brand-Bold\"),),
                        SizedBox(height: 20.0),
                        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.blueAccent,),
                                SizedBox(width: 10.0,),
                                Text(\"Buscar una ubicación de entrega\")
                              ],
                            ),
                          ),
                        ),
                        SizedBox(height: 24.0),
                        Row(
                          children: [
                            Icon(Icons.home,color: Colors.grey,),
                            SizedBox(width: 12.0,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(\"Agregar Casa\"),
                                SizedBox(height: 4.0,),
                                Text(\"La dirección de su casa\", style: TextStyle(color: Colors.grey[500], 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(\"Agregar Trabajo\"),
                                SizedBox(height: 4.0,),
                                Text(\"La dirección de su trabajo\", style: TextStyle(color: Colors.grey[500], fontSize: 12.0),),

                              ],
                            ),
                          ],
                        ),

                      ],
                    ),
                  ),
                ),
              )
            ],
          ),
        );
      }
    }


<!-- end snippet -->

我希望和你能帮助给我一个解决方案或给我一条路径,以便我可以继续,因为我不知道该怎么做。

  • 您是否已将 this package 添加到您的项目中?如果我没记错的话,网络平台上的谷歌地图没有它就无法工作。
  • 是的,我有那个包裹,我继续我的错误

标签: flutter compiler-errors maps


【解决方案1】:

发生错误是因为您尝试在网络上使用 google_maps_flutter - 它仅支持 Android 和 iOS。如果你在 Flutter for web 上添加谷歌地图插件,你需要使用google_maps_flutter_web

【讨论】:

    【解决方案2】:

    使用终端而不是调试控制台进行调试。

    在终端中运行它:

    flutter run -d chrome --web-renderer html
    

    【讨论】:

      猜你喜欢
      • 2022-08-13
      • 2022-01-16
      • 1970-01-01
      • 2021-11-26
      • 2021-11-24
      • 2021-12-20
      • 2021-11-27
      • 2022-01-21
      • 2021-12-04
      相关资源
      最近更新 更多