flutter运行百度地图页面app就崩了,其他页面正常运行

1. 错误描述:

目前只是做安卓端,虚拟机、安卓真机上运行都是一样的结果,所有的配置都是按照百度官方的配置操作的,反复检查了好几遍,百度里面也找了下答案,但是没有一个能解决问题的,本人只会前端,一些原生的报错真看不懂,麻烦哪位高手解决下!

2. 地图展示页面代码:

import 'package:flutter/material.dart';
import 'package:flutter_bmfbase/BaiduMap/bmfmap_base.dart';
import 'package:flutter_bmfmap/BaiduMap/bmfmap_map.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ShowMapPage extends StatefulWidget {
  @override
  _ShowMapPageState createState() => _ShowMapPageState();
}

class _ShowMapPageState extends State<ShowMapPage> {
  BMFMapController myMapController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('地图显示'), centerTitle: true),
      body: generateMap(),
    );
  }

  /// 创建完成回调
  void onBMFMapCreated(BMFMapController controller) {
    myMapController = controller;

    /// 地图加载回调
    myMapController?.setMapDidLoadCallback(callback: () {
      print('mapDidLoad-地图加载完成');
    });
  }

  /// 设置地图参数
  BMFMapOptions initMapOptions() {
    BMFMapOptions mapOptions = BMFMapOptions(
        center: BMFCoordinate(39.917215, 116.380341),
        zoomLevel: 12,
        mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 0));
    return mapOptions;
  }

  /// 创建地图
  Container generateMap() {
    return Container(
      height: 1.hp,
      width: 1.wp,
      child: BMFMapWidget(
        onBMFMapCreated: (controller) {
          onBMFMapCreated(controller);
        },
        mapOptions: initMapOptions(),
      ),
    );
  }

  /// 创建控制栏
  Widget generateControlBar() {
    throw UnimplementedError();
  }
}

3. 插件依赖:

flutter_bmflocation: ^1.0.2;flutter_bmfmap: ^1.0.2

4. 报错信息:

E/flutter ( 1650): [ERROR:flutter/shell/platform/android/platform_view_android_jni_impl.cc(43)] java.lang.ExceptionInInitializerError
E/flutter ( 1650): at com.baidu.mapsdkplatform.comapi.map.m.a(Unknown Source:0)
E/flutter ( 1650): at com.baidu.mapapi.map.MapView.a(Unknown Source:2)
E/flutter ( 1650): at com.baidu.mapapi.map.MapView.(Unknown Source:20)
E/flutter ( 1650): at com.baidu.flutter_bmfmap.map.FlutterMapView.init(FlutterMapView.java:72)
E/flutter ( 1650): at com.baidu.flutter_bmfmap.map.FlutterMapView.(FlutterMapView.java:64)
E/flutter ( 1650): at com.baidu.flutter_bmfmap.MapViewFactory.create(MapViewFactory.java:38)
E/flutter ( 1650): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186)
E/flutter ( 1650): at android.app.Dialog.dispatchOnCreate(Dialog.java:419)
E/flutter ( 1650): at android.app.Dialog.show(Dialog.java:313)
E/flutter ( 1650): at android.app.Presentation.show(Presentation.java:257)
E/flutter ( 1650): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:95)
E/flutter ( 1650): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48)
E/flutter ( 1650): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:207)
E/flutter ( 1650): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
E/flutter ( 1650): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/flutter ( 1650): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter ( 1650): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter ( 1650): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter ( 1650): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 1650): at android.os.MessageQueue.next(MessageQueue.java:335)
E/flutter ( 1650): at android.os.Looper.loop(Looper.java:183)
E/flutter ( 1650): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 1650): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 1650): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 1650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 1650): Caused by: java.lang.IllegalStateException: BDMapSDKException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
E/flutter ( 1650): at com.baidu.mapsdkplatform.comapi.a.e(Unknown Source:9)
E/flutter ( 1650): at com.baidu.mapapi.BMapManager.getContext(Unknown Source:4)
E/flutter ( 1650): at com.baidu.mapsdkplatform.comapi.map.m.(Unknown Source:0)

讨论数量: 1

是否初始化了SDK 或者 配置了继承BmfMapApplication的 Application

3个月前 评论
Dxismd (楼主) 3个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!