Explorar o código

[fix]修复录音界面返回通知未关闭的问题

zk hai 1 ano
pai
achega
644d241598
Modificáronse 2 ficheiros con 44 adicións e 34 borrados
  1. 9 6
      lib/module/record/controller.dart
  2. 35 28
      lib/module/record/view.dart

+ 9 - 6
lib/module/record/controller.dart

@@ -24,10 +24,7 @@ import 'package:path_provider/path_provider.dart';
 import 'package:record/record.dart';
 import 'package:uuid/uuid.dart';
 import 'package:wakelock_plus/wakelock_plus.dart';
-
-import '../../dialog/desktop_shortcut_dialog.dart';
 import '../../utils/pcm_wav_converter.dart';
-import '../../widget/frame_animation_view.dart';
 
 class RecordController extends BaseController {
   static const String keyLastRecordId = "last_record_id";
@@ -94,10 +91,10 @@ class RecordController extends BaseController {
     WidgetsBinding.instance
         .addPostFrameCallback((_) => FlutterForegroundTask.init(
               androidNotificationOptions: AndroidNotificationOptions(
-                channelId: StringName.recordNotificationChannelId,
-                channelName: StringName.recordNotificationChannelName,
+                channelId: StringName.recordNotificationChannelId.tr,
+                channelName: StringName.recordNotificationChannelName.tr,
                 channelDescription:
-                    StringName.recordNotificationChannelDescription,
+                    StringName.recordNotificationChannelDescription.tr,
                 channelImportance: NotificationChannelImportance.LOW,
                 priority: NotificationPriority.LOW,
               ),
@@ -357,4 +354,10 @@ class RecordController extends BaseController {
     File file = File("${documentDir.path}/.atmob/record/$lastRecordId");
     return await file.exists() && await file.length() > 0;
   }
+
+  canPop() async {
+    if (currentStatus.value == RecordStatus.recording) {
+      return _stopRecord();
+    }
+  }
 }

+ 35 - 28
lib/module/record/view.dart

@@ -36,37 +36,44 @@ class RecordPage extends BasePage<RecordController> {
 
   @override
   Widget buildBody(BuildContext context) {
-    return Stack(alignment: Alignment.bottomCenter, children: [
-      _buildBottomGradient(),
-      Scaffold(
-        appBar: AppBar(
-          leading: IconButton(
-            icon: const Icon(Icons.arrow_back_ios_new_rounded),
-            color: ColorName.white,
-            onPressed: () {
-              controller.onBackClick();
-            },
+    return PopScope(
+      canPop: false,
+      onPopInvokedWithResult: (bool didPop, dynamic result) async {
+        await controller.canPop();
+        Get.back();
+      },
+      child: Stack(alignment: Alignment.bottomCenter, children: [
+        _buildBottomGradient(),
+        Scaffold(
+          appBar: AppBar(
+            leading: IconButton(
+              icon: const Icon(Icons.arrow_back_ios_new_rounded),
+              color: ColorName.white,
+              onPressed: () {
+                controller.onBackClick();
+              },
+            ),
+            scrolledUnderElevation: 0,
+            backgroundColor: ColorName.transparent,
+            systemOverlayStyle: SystemUiOverlayStyle.light,
+            actions: [
+              _buildAddShortcut(true),
+            ],
           ),
-          scrolledUnderElevation: 0,
           backgroundColor: ColorName.transparent,
-          systemOverlayStyle: SystemUiOverlayStyle.light,
-          actions: [
-            _buildAddShortcut(true),
-          ],
-        ),
-        backgroundColor: ColorName.transparent,
-        body: Flex(
-          direction: Axis.vertical,
-          children: [
-            _buildRecordStatus(),
-            const Spacer(flex: 271),
-            _buildRecordAnim(),
-            const Spacer(flex: 407),
-            _buildRecordControl(),
-          ],
+          body: Flex(
+            direction: Axis.vertical,
+            children: [
+              _buildRecordStatus(),
+              const Spacer(flex: 271),
+              _buildRecordAnim(),
+              const Spacer(flex: 407),
+              _buildRecordControl(),
+            ],
+          ),
         ),
-      ),
-    ]);
+      ]),
+    );
   }
 
   Widget _buildAddShortcut(bool visible) {