4.0.0 (#24)
* feat: 调整插件接口 * feat: 增加 `Logger` 类 * fix: 部分参数改为可选参数 * fix: 调整接口 * fix: 重命名 AdvertiseData 为 Advertisement * fix: 移除 `Logger.level` 属性 * fix: 适配 4.0.0 * fix: 更新依赖项 * fix: 优化导入方式 * fix: 修改版本号 * fix: 适配 4.0.0 * feat: 部分适配 4.0.0 * feat: 适配 4.0.0 * feat: 适配 4.0.0 * fix: 调整接口 * feat: 调整日志接口 * fix: 修复日志错误 * fix: 临时提交 * draft: 临时提交 * fix: 使用 log_service 插件替换 logging 插件 * fix: 更新 log_service 版本 * fix: 4.0.0 * feat: 4.0.0 * feat: 4.0.0
This commit is contained in:
@ -8,22 +8,35 @@ import 'package:convert/convert.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
CentralManager get centralManager => CentralManager.instance;
|
||||
PeripheralManager get peripheralManager => PeripheralManager.instance;
|
||||
|
||||
void main() {
|
||||
runZonedGuarded(onStartUp, onCrashed);
|
||||
}
|
||||
|
||||
void onStartUp() async {
|
||||
Logger.root.onRecord.listen(onLogRecord);
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await CentralManager.instance.setUp();
|
||||
await PeripheralManager.instance.setUp();
|
||||
await centralManager.setUp();
|
||||
await peripheralManager.setUp();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
void onCrashed(Object error, StackTrace stackTrace) {
|
||||
Logger.root.shout('App crached.', error, stackTrace);
|
||||
}
|
||||
|
||||
void onLogRecord(LogRecord record) {
|
||||
log(
|
||||
'$error',
|
||||
error: error,
|
||||
stackTrace: stackTrace,
|
||||
record.message,
|
||||
time: record.time,
|
||||
sequenceNumber: record.sequenceNumber,
|
||||
level: record.level.value,
|
||||
name: record.loggerName,
|
||||
zone: record.zone,
|
||||
error: record.error,
|
||||
stackTrace: record.stackTrace,
|
||||
);
|
||||
}
|
||||
|
||||
@ -138,8 +151,6 @@ class _HomeViewState extends State<HomeView> {
|
||||
}
|
||||
}
|
||||
|
||||
CentralManager get centralManager => CentralManager.instance;
|
||||
|
||||
class ScannerView extends StatefulWidget {
|
||||
const ScannerView({super.key});
|
||||
|
||||
@ -237,7 +248,7 @@ class _ScannerViewState extends State<ScannerView> {
|
||||
builder: (context, discoveredEventArgs, child) {
|
||||
// final items = discoveredEventArgs;
|
||||
final items = discoveredEventArgs
|
||||
.where((eventArgs) => eventArgs.advertiseData.name != null)
|
||||
.where((eventArgs) => eventArgs.advertisement.name != null)
|
||||
.toList();
|
||||
return ListView.separated(
|
||||
itemBuilder: (context, i) {
|
||||
@ -245,8 +256,8 @@ class _ScannerViewState extends State<ScannerView> {
|
||||
final item = items[i];
|
||||
final uuid = item.peripheral.uuid;
|
||||
final rssi = item.rssi;
|
||||
final advertiseData = item.advertiseData;
|
||||
final name = advertiseData.name;
|
||||
final advertisement = item.advertisement;
|
||||
final name = advertisement.name;
|
||||
return ListTile(
|
||||
onTap: () async {
|
||||
final discovering = this.discovering.value;
|
||||
@ -273,7 +284,7 @@ class _ScannerViewState extends State<ScannerView> {
|
||||
clipBehavior: Clip.antiAlias,
|
||||
builder: (context) {
|
||||
final manufacturerSpecificData =
|
||||
advertiseData.manufacturerSpecificData;
|
||||
advertisement.manufacturerSpecificData;
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
@ -428,7 +439,7 @@ class _PeripheralViewState extends State<PeripheralView> {
|
||||
},
|
||||
);
|
||||
rssiTimer = Timer.periodic(
|
||||
const Duration(seconds: 1),
|
||||
const Duration(seconds: 5),
|
||||
(timer) async {
|
||||
final state = this.state.value;
|
||||
if (state) {
|
||||
@ -458,7 +469,7 @@ class _PeripheralViewState extends State<PeripheralView> {
|
||||
}
|
||||
|
||||
PreferredSizeWidget buildAppBar(BuildContext context) {
|
||||
final title = eventArgs.advertiseData.name ?? '<EMPTY NAME>';
|
||||
final title = eventArgs.advertisement.name ?? '';
|
||||
return AppBar(
|
||||
title: Text(title),
|
||||
actions: [
|
||||
@ -804,8 +815,6 @@ class _PeripheralViewState extends State<PeripheralView> {
|
||||
}
|
||||
}
|
||||
|
||||
PeripheralManager get peripheralManager => PeripheralManager.instance;
|
||||
|
||||
class AdvertiserView extends StatefulWidget {
|
||||
const AdvertiserView({super.key});
|
||||
|
||||
@ -813,7 +822,8 @@ class AdvertiserView extends StatefulWidget {
|
||||
State<AdvertiserView> createState() => _AdvertiserViewState();
|
||||
}
|
||||
|
||||
class _AdvertiserViewState extends State<AdvertiserView> {
|
||||
class _AdvertiserViewState extends State<AdvertiserView>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final ValueNotifier<BluetoothLowEnergyState> state;
|
||||
late final ValueNotifier<bool> advertising;
|
||||
late final ValueNotifier<List<Log>> logs;
|
||||
@ -856,11 +866,11 @@ class _AdvertiserViewState extends State<AdvertiserView> {
|
||||
final value = Uint8List.fromList([0x01, 0x02, 0x03]);
|
||||
await peripheralManager.sendReadCharacteristicReply(
|
||||
central,
|
||||
characteristic,
|
||||
id,
|
||||
offset,
|
||||
status,
|
||||
value,
|
||||
characteristic: characteristic,
|
||||
id: id,
|
||||
offset: offset,
|
||||
status: status,
|
||||
value: value,
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -884,10 +894,10 @@ class _AdvertiserViewState extends State<AdvertiserView> {
|
||||
const status = true;
|
||||
await peripheralManager.sendWriteCharacteristicReply(
|
||||
central,
|
||||
characteristic,
|
||||
id,
|
||||
offset,
|
||||
status,
|
||||
characteristic: characteristic,
|
||||
id: id,
|
||||
offset: offset,
|
||||
status: status,
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -911,8 +921,8 @@ class _AdvertiserViewState extends State<AdvertiserView> {
|
||||
final value = Uint8List.fromList([0x03, 0x02, 0x01]);
|
||||
await peripheralManager.notifyCharacteristicValueChanged(
|
||||
central,
|
||||
characteristic,
|
||||
value,
|
||||
characteristic: characteristic,
|
||||
value: value,
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -991,14 +1001,14 @@ class _AdvertiserViewState extends State<AdvertiserView> {
|
||||
],
|
||||
);
|
||||
await peripheralManager.addService(service);
|
||||
final advertiseData = AdvertiseData(
|
||||
final advertisement = Advertisement(
|
||||
name: 'flutter',
|
||||
manufacturerSpecificData: ManufacturerSpecificData(
|
||||
id: 0x2e19,
|
||||
data: Uint8List.fromList([0x01, 0x02, 0x03]),
|
||||
),
|
||||
);
|
||||
await peripheralManager.startAdvertising(advertiseData);
|
||||
await peripheralManager.startAdvertising(advertisement);
|
||||
advertising.value = true;
|
||||
}
|
||||
|
||||
|
@ -15,15 +15,15 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "3.0.4"
|
||||
version: "4.0.0"
|
||||
bluetooth_low_energy_platform_interface:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: bluetooth_low_energy_platform_interface
|
||||
sha256: "200e686247808591b6d3e355642ba296f0f651466c72efdd701be34116971473"
|
||||
sha256: a01819f4ef89d033edaa979465ec8c3af13b2618dc718d90fe681be91b6c4356
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
version: "4.0.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -102,10 +102,10 @@ packages:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
|
||||
sha256: ad76540d21c066228ee3f9d1dad64a9f7e46530e8bb7c85011a88bc1fd874bc5
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "3.0.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -133,10 +133,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
|
||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "3.0.0"
|
||||
log_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: log_service
|
||||
sha256: "21124936899e227d1779268077921d46d57456e2592d1562e455be273594e2e4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -17,7 +17,7 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
bluetooth_low_energy_platform_interface: ^3.0.0
|
||||
bluetooth_low_energy_platform_interface: ^4.0.0
|
||||
bluetooth_low_energy_android:
|
||||
# When depending on this package from a real application you should use:
|
||||
# bluetooth_low_energy: ^x.y.z
|
||||
@ -43,7 +43,7 @@ dev_dependencies:
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^2.0.0
|
||||
flutter_lints: ^3.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
Reference in New Issue
Block a user