Browse Source

修改引导页耳机唤醒监听

weicu
tanlongsheng 1 year ago
parent
commit
8e45063c2c
  1. 24
      lib/data/services/novice_guide_service.dart
  2. 8
      lib/modules/home/views/home_view.dart

24
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<dynamic>? _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();
}
}

8
lib/modules/home/views/home_view.dart

@ -100,7 +100,9 @@ class HomeView extends GetView<HomeController> {
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<HomeController> {
() => IntroOverlayBuilder.homeBuilder(
params,
controller.noviceGuideService.isWakeup.value,
onNext: () {},
onNext: () {
controller.noviceGuideService.closeWakeupListen();
},
),
);
},

Loading…
Cancel
Save