import 'dart:async'; import 'package:flutter/services.dart'; import 'amap_marker.dart'; class AmapViewController { MethodChannel _methodChannel; StreamController _guideStreamController; Stream get guideStream => _guideStreamController.stream; void init(int id) { _methodChannel = MethodChannel("com.i2edu.mapView/map_view_$id"); _methodChannel.setMethodCallHandler(platformCallHandler); _guideStreamController = StreamController.broadcast(); } Future platformCallHandler(MethodCall call) async { try { if (call.method == "guide") { _guideStreamController.add(call.arguments); } } catch (ex) { print('Unexpected error: $ex'); } return null; } Future setMapMarkers(List markers) async { assert(_methodChannel != null); return await _methodChannel.invokeMethod( "setMarkers", {"markers": markers.map((f) => f.toMap()).toList()}); } Future onCreateMapView() async { assert(_methodChannel != null); return await _methodChannel.invokeMethod('onCreate'); } Future onPauseMapView() async { assert(_methodChannel != null); return await _methodChannel.invokeMethod('onPause'); } Future onResumeMapView() async { assert(_methodChannel != null); return await _methodChannel.invokeMethod('onResume'); } void dispose() { if (!_guideStreamController.isClosed) { _guideStreamController.close(); } } }