main.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/services.dart';
  4. import 'dart:math';
  5. void main() {
  6. runApp(const MyApp());
  7. }
  8. class MyApp extends StatelessWidget {
  9. const MyApp({super.key});
  10. // This widget is the root of your application.
  11. @override
  12. Widget build(BuildContext context) {
  13. return MaterialApp(
  14. title: 'Flutter Demo',
  15. theme: ThemeData(
  16. colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
  17. ),
  18. home: const MyHomePage(title: 'Flutter Demo Home Page'),
  19. );
  20. }
  21. }
  22. class MyHomePage extends StatefulWidget {
  23. const MyHomePage({super.key, required this.title});
  24. final String title;
  25. @override
  26. State<MyHomePage> createState() => _MyHomePageState();
  27. }
  28. class _MyHomePageState extends State<MyHomePage> {
  29. MethodChannel? _methodChannel;
  30. void onViewCreated(int viewId) {
  31. _methodChannel = MethodChannel("atmob_map_method_channel");
  32. _methodChannel?.setMethodCallHandler((call) {
  33. if (call.method == "marker#onTap") {
  34. debugPrint("Marker tapped: ${call.arguments}");
  35. }
  36. return Future.value(null);
  37. });
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return CupertinoPageScaffold(
  42. child: Stack(
  43. children: [
  44. UiKitView(
  45. viewType: "com.atmob.flutter.map",
  46. onPlatformViewCreated: onViewCreated
  47. ),
  48. Positioned(
  49. bottom: 0,
  50. left: 0,
  51. right: 0,
  52. child: Column(
  53. children: [
  54. CupertinoButton(
  55. child: Text("Random Position"),
  56. onPressed: () {
  57. _methodChannel?.invokeMethod("map#moveCamera", {
  58. "latitude": Random().nextDouble() * (40.0 - 22.0) + 22.0,
  59. "longitude": Random().nextDouble() * (120.0 - 110.0) + 110.0,
  60. "zoom": 0.05
  61. });
  62. }),
  63. CupertinoButton(
  64. child: Text("Add Marker"),
  65. onPressed: () {
  66. _methodChannel?.invokeMethod("marker#updateOrAddMarkers", {
  67. "id": "marker_${Random().nextInt(1000000)}",
  68. "latitude": Random().nextDouble() * (40.0 - 22.0) + 22.0,
  69. "longitude": Random().nextDouble() * (120.0 - 110.0) + 110.0,
  70. "markerName": "Marker ${Random().nextInt(1000000)}",
  71. "isSelected": false
  72. });
  73. }
  74. ),
  75. CupertinoButton(
  76. child: Text("Clear Markers"),
  77. onPressed: () {
  78. _methodChannel?.invokeMethod("map#clear");
  79. }
  80. ),
  81. CupertinoButton(
  82. child: Text("Add Polyline"),
  83. onPressed: () {
  84. _methodChannel?.invokeMethod("polyline#addPolyline", {
  85. "points": List.generate(20, (_) => {
  86. "latitude": Random().nextDouble() * (40.0 - 22.0) + 22.0,
  87. "longitude": Random().nextDouble() * (120.0 - 110.0) + 110.0
  88. })
  89. });
  90. }
  91. )
  92. ],
  93. )
  94. )
  95. ],
  96. ),
  97. );
  98. }
  99. }