Browse Source

update: 修改不关闭stream controller

hwh97 4 years ago
parent
commit
ca3c6c2cfa
2 changed files with 10 additions and 10 deletions
  1. 1 1
      example/lib/main.dart
  2. 9 9
      lib/amap_location.dart

+ 1 - 1
example/lib/main.dart

@@ -76,7 +76,7 @@ class HomePageState extends State<HomePage> {
                       locationMode: LocationMode.Battery_Saving,));
                 AmapLocation.instance.locationStream.listen((d) {
                   print(d.city);
-                  AmapLocation.instance.disposed();
+                  AmapLocation.instance.closeLocation();
                   // stop location when isOnceLocation is true
 //                     AmapLocation.instance.disposed();
                 });

+ 9 - 9
lib/amap_location.dart

@@ -31,22 +31,22 @@ class AmapLocation {
   }
 
   Future<void> startLocation({LocationOption options}) async {
-    if (_locationStreamController == null) {
-      _locationStreamController =
-          StreamController<LocationResultEntity>.broadcast();
-    }
     return await _channel.invokeMethod(
         'startLocation', options?.toMap() ?? LocationOption().toMap());
   }
 
-  Future<void> disposed() async {
-    if (!_locationStreamController.isClosed) {
-      await _locationStreamController.close();
-      _locationStreamController=null;
-    }
+  Future<void> closeLocation() async {
     return await _channel.invokeMethod("closeLocation");
   }
 
+  // Future<void> disposed() async {
+  //   if (!_locationStreamController.isClosed) {
+  //     await _locationStreamController.close();
+  //     _locationStreamController=null;
+  //   }
+  //   return await _channel.invokeMethod("closeLocation");
+  // }
+
   Future<void> platformCallHandler(MethodCall call) async {
     try {
       if (call.method == "location") {