import 'dart:io'; import 'package:amap_location/amap_view_controller.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; typedef OnPlatformViewCreated(AmapViewController controller); class AmapView extends StatefulWidget { final OnPlatformViewCreated onPlatformViewCreated; const AmapView({Key key, this.onPlatformViewCreated}) : super(key: key); @override _AmapViewState createState() => _AmapViewState(); } class _AmapViewState extends State { static const String viewType = "com.i2edu.mapView"; @override Widget build(BuildContext context) { return Platform.isAndroid ? AndroidView( viewType: viewType, creationParams: {}, creationParamsCodec: const StandardMessageCodec(), onPlatformViewCreated: onPlatformViewCreated, ) : UiKitView( viewType: viewType, creationParams: {}, creationParamsCodec: const StandardMessageCodec(), onPlatformViewCreated: onPlatformViewCreated, ); } void onPlatformViewCreated(int id) { final AmapViewController controller = AmapViewController(id); if (widget.onPlatformViewCreated != null) { widget.onPlatformViewCreated(controller); } } }