Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

weicu
liwei1dao 1 year ago
parent
commit
133b71ed8f
  1. 73
      lib/modules/meeting/controllers/meeting_connect_controller.dart
  2. 115
      lib/modules/meeting/views/meeting_connect_view.dart
  3. 2
      pubspec.yaml

73
lib/modules/meeting/controllers/meeting_connect_controller.dart

@ -1,3 +1,74 @@
import 'dart:async';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class MeetingConnectController extends GetxController {} class MeetingConnectController extends GetxController {
RxString stateStr = '搜索中...'.obs;
RxBool isRescan = false.obs;
RxBool isImportedFiles = false.obs;
late StreamSubscription<List<ScanResult>> _scanResultsSubscription;
late StreamSubscription<bool> _isScanningSubscription;
BluetoothDevice? _device;
@override
void onInit() {
super.onInit();
_scanResultsSubscription = FlutterBluePlus.scanResults.listen((results) {
for (ScanResult item in results) {
_handlerScanResult(item);
}
});
_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
if (!state && _device == null) {
stateStr.value = '未搜索到 AI PEN 设备';
isRescan.value = true;
} else {
stateStr.value = '搜索中...';
isRescan.value = false;
}
});
startScan();
}
@override
void onClose() {
_scanResultsSubscription.cancel();
_isScanningSubscription.cancel();
_stopScan();
_disconnect();
super.onClose();
}
Future<void> startScan() async {
await FlutterBluePlus.startScan(
timeout: const Duration(seconds: 15),
withServices: [
Guid('FFF0'),
],
withNames: ['AI PEN'],
);
}
Future<void> _stopScan() async {
await FlutterBluePlus.stopScan();
}
Future<void> _connect() async {
await _device?.connect();
}
Future<void> _disconnect() async {
await _device?.disconnect();
}
void _handlerScanResult(ScanResult result) async {
if (result.device.platformName == 'AI PEN') {
_device = result.device;
await _stopScan();
await _connect();
stateStr.value = '已连接到 AI PEN 设备';
}
}
}

115
lib/modules/meeting/views/meeting_connect_view.dart

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../controllers/meeting_connect_controller.dart'; import '../controllers/meeting_connect_controller.dart';
@ -8,6 +9,118 @@ class MeetingConnectView extends GetView<MeetingConnectController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const Placeholder(); final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDarkMode ? Colors.black : Colors.grey[50],
appBar: _buildAppBar(isDarkMode),
body: _buildBody(isDarkMode),
);
}
PreferredSizeWidget _buildAppBar(bool isDarkMode) {
return AppBar(
backgroundColor: isDarkMode ? Colors.black : Colors.white,
elevation: 0.5,
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: isDarkMode ? Colors.white : Colors.black,
size: 20.sp,
),
onPressed: () => Get.back(),
),
title: Text(
'蓝牙连接',
style: TextStyle(
fontSize: 17.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.white : Colors.black,
),
),
centerTitle: true,
);
}
Widget _buildBody(bool isDarkMode) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(
() => Text(
controller.stateStr.value,
style: TextStyle(
fontSize: 20.sp,
color: isDarkMode ? Colors.white : Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Obx(
() => controller.isRescan.value
? Padding(
padding: EdgeInsets.only(top: 20.w),
child: _button('重新连接', Icons.refresh, onTap: () {
controller.startScan();
}),
)
: const SizedBox(),
),
Obx(
() => controller.isImportedFiles.value
? Padding(
padding: EdgeInsets.only(top: 30.w),
child: Text(
'检测到有新文件,是否导入',
style: TextStyle(
fontSize: 16.sp,
color: isDarkMode ? Colors.white70 : Colors.black54,
),
),
)
: const SizedBox(),
),
Obx(
() => controller.isImportedFiles.value
? _button('导入文件', Icons.file_download, onTap: () {})
: const SizedBox(),
),
],
),
);
}
Widget _button(String text, IconData icon, {Function()? onTap}) {
return GestureDetector(
onTap: onTap,
child: Container(
width: 150.w,
height: 42.w,
margin: EdgeInsets.symmetric(vertical: 10.w),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(42.w),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
color: Colors.white,
size: 20.sp,
),
5.horizontalSpace,
Text(
text,
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
),
],
),
),
);
} }
} }

2
pubspec.yaml

@ -35,7 +35,7 @@ dependencies:
crypto: ^3.0.3 crypto: ^3.0.3
flutter_tts: ^4.2.2 flutter_tts: ^4.2.2
logger: ^2.0.2+1 logger: ^2.0.2+1
flutter_blue_plus: ^1.31.16 flutter_blue_plus: ^1.35.5
just_audio: ^0.9.36 just_audio: ^0.9.36
webview_flutter: ^4.13.0 webview_flutter: ^4.13.0
flutter_easyloading: ^3.0.5 flutter_easyloading: ^3.0.5

Loading…
Cancel
Save