From 8e45063c2c0ebcefa829aeb96cdbaa015fc16738 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Mon, 4 Aug 2025 20:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=95=E5=AF=BC=E9=A1=B5?= =?UTF-8?q?=E8=80=B3=E6=9C=BA=E5=94=A4=E9=86=92=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/services/novice_guide_service.dart | 24 +++++++++++++++++++++ lib/modules/home/views/home_view.dart | 8 +++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/data/services/novice_guide_service.dart b/lib/data/services/novice_guide_service.dart index c26e7adc8..ad7b19451 100644 --- a/lib/data/services/novice_guide_service.dart +++ b/lib/data/services/novice_guide_service.dart @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:ble_service/ble_service.dart'; import 'package:flutter_intro/flutter_intro.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; @@ -5,6 +8,9 @@ import 'package:get_storage/get_storage.dart'; class NoviceGuideService extends GetxService { final GetStorage _storage = GetStorage(); + final BleService _bleService = BleService(); + StreamSubscription? _statusSubscription; + bool isHomeGuide = false; bool isAIGuide = true; @@ -58,6 +64,12 @@ class NoviceGuideService extends GetxService { // isAIGuide = _storage.read('ai_guide') ?? false; } + @override + void onClose() { + closeWakeupListen(); + super.onClose(); + } + void startHomeGuide() async { if (!isHomeGuide) { await Future.delayed(const Duration(milliseconds: 200)); @@ -75,4 +87,16 @@ class NoviceGuideService extends GetxService { Intro.of(Get.context!).start(group: 'ai'); } } + + void startWakeupListen() { + _statusSubscription = _bleService.onStatusUpdated.listen((event) { + if (event is Map && event['type'] == 'wakeup') { + isWakeup.value = true; + } + }); + } + + void closeWakeupListen() { + _statusSubscription?.cancel(); + } } diff --git a/lib/modules/home/views/home_view.dart b/lib/modules/home/views/home_view.dart index 5f993a405..e1a68c9a1 100644 --- a/lib/modules/home/views/home_view.dart +++ b/lib/modules/home/views/home_view.dart @@ -100,7 +100,9 @@ class HomeView extends GetView { return IntroOverlayBuilder.aiBuilder( params, '欢迎使用Voitrans!首先,让我们唤醒你的专属 AI—— 小言', - onNext: () {}, + onNext: () { + controller.noviceGuideService.startWakeupListen(); + }, ); }, builder: (BuildContext context, GlobalKey key) => SizedBox( @@ -130,7 +132,9 @@ class HomeView extends GetView { () => IntroOverlayBuilder.homeBuilder( params, controller.noviceGuideService.isWakeup.value, - onNext: () {}, + onNext: () { + controller.noviceGuideService.closeWakeupListen(); + }, ), ); },