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(); + }, ), ); },