amap_view.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import 'dart:io';
  2. import 'package:amap_location/amap_view_controller.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. typedef OnPlatformViewCreated(AmapViewController controller);
  6. class AmapView extends StatefulWidget {
  7. final OnPlatformViewCreated onPlatformViewCreated;
  8. const AmapView({Key key, this.onPlatformViewCreated}) : super(key: key);
  9. @override
  10. _AmapViewState createState() => _AmapViewState();
  11. }
  12. class _AmapViewState extends State<AmapView> {
  13. static const String viewType = "com.i2edu.mapView";
  14. @override
  15. Widget build(BuildContext context) {
  16. return Platform.isAndroid
  17. ? AndroidView(
  18. viewType: viewType,
  19. creationParams: {},
  20. creationParamsCodec: const StandardMessageCodec(),
  21. onPlatformViewCreated: onPlatformViewCreated,
  22. )
  23. : UiKitView(
  24. viewType: viewType,
  25. creationParams: {},
  26. creationParamsCodec: const StandardMessageCodec(),
  27. onPlatformViewCreated: onPlatformViewCreated,
  28. );
  29. }
  30. void onPlatformViewCreated(int id) {
  31. final AmapViewController controller = AmapViewController(id);
  32. if (widget.onPlatformViewCreated != null) {
  33. widget.onPlatformViewCreated(controller);
  34. }
  35. }
  36. }