构建 GoogleMap 时抛出以下 JSNoSuchMethodError(脏,依赖项:[方向性],

问题描述 投票:0回答:1

我已经输入了我所知道的所有内容来添加谷歌地图以在颤振移动应用程序中添加地图。我已经让我的 login_screen.dart 成功与 firebase 数据库连接,并且当页面仅包含文本时已经成功显示 home_page 。当我输入谷歌地图时,在调试控制台上显示如下:

══╡小部件库捕获异常╞═════════════════════════════ ═══════════ ═══════════════════ 构建 GoogleMap 时抛出以下 JSNoSuchMethodError(脏,依赖项: [方向性],状态:_GoogleMapState#587c7): 类型错误:无法读取未定义的属性(读取“地图”)

导致错误的相关小部件是: 谷歌地图 GoogleMap:file:///D:/AAA%20KULIAH/Semester%205/rpl_agile_implementation/smlog_delivery/lib/pages/home_page.dart:24:11

抛出异常时,堆栈是这样的: 包/google_maps_flutter_web/src/convert.dart 100:30 _gmapTypeIDForPluginType 包/google_maps_flutter_web/src/convert.dart 43:25 _configurationAndStyleToGmapsOptions 包/google_maps_flutter_web/src/google_maps_controller.dart 173:32 初始化 包/google_maps_flutter_web/src/google_maps_flutter_web.dart 311:8 包/google_maps_flutter_web/src/google_maps_flutter_web.dart 311:8 buildViewWithConfiguration 包/google_maps_flutter/src/google_map.dart 321:47 构建 包/flutter/src/widgets/framework.dart 5583:27 构建 packages/flutter/src/widgets/framework.dart 5471:15 PerformRebuild ... ════════════════════════════════════════ ══════════ ════════════════════════════════════════ ══════════

这是我的 main.dart 文件:

`import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:smlog_delivery/authentication/login_screen.dart';
import 'package:smlog_delivery/firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: Colors.black,
      ),
      home: LoginScreen(),
    );
  }
}`

这是我的login_screen.dart:

`import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:smlog_delivery/authentication/login_screen.dart';
import 'package:smlog_delivery/firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: Colors.black,
      ),
      home: LoginScreen(),
    );
  }
}
`

这是我的 home_page.dart :


`import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:smlog_delivery/global/global_var.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final Completer<GoogleMapController> googleMapCompleterController =
      Completer<GoogleMapController>();
  GoogleMapController? controllerGoogleMap;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          GoogleMap(
            mapType: MapType.normal,
            myLocationEnabled: true,
            initialCameraPosition: googlePlexInitialPosition,
            onMapCreated: (GoogleMapController mapController) {
              controllerGoogleMap = mapController;

              googleMapCompleterController.complete(controllerGoogleMap);
            },
          ),
        ],
      ),
    );
  }
}`

我将initialCameraPosition:googlePlexInitialPosition代码放在我的lib中的文件global_var.dart中:

`import 'package:google_maps_flutter/google_maps_flutter.dart';

String namaUser = "";
//my API Key already inserted to AndroidManifest.xml
String googleMapKey = "...";

const CameraPosition googlePlexInitialPosition = CameraPosition(
  target: LatLng(37.42796133580664, -122.085749655962),
  zoom: 14.4746,
);`

我已经检查过代码没有错误,但是当我运行应用程序时,它变成了这样。我已经成功地将 flutter 与 firebase 与 flutterfire 连接起来,但对于这个问题我感到困惑。有什么我忘记补充的吗?

我已经打开了链接中的 flutter 文档,但尝试这样做有点困惑。因为文档仅在 main.dart 中显示。我真的不知道该怎么办。我将非常感谢能够解决这个问题的人。

flutter firebase google-maps firebase-authentication
1个回答
0
投票

运行 flutter run -d chrome 时,在此 Web 应用程序的 flutter master 上定期(并非总是)出现此错误。刷新 chrome 选项卡有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.