led_bt_jl_ota 0.0.14
led_bt_jl_ota: ^0.0.14 copied to clipboard
杰理ota的封装
example/lib/main.dart
import 'dart:io';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:led_bt_jl_ota/led_bt_jl_ota.dart';
import 'package:led_bt_jl_ota_example/testled/ConnectUtil.dart';
import 'package:oktoast/oktoast.dart';
import 'BleDevicePage.dart';
import 'ble/permission/PermisionUtil.dart';
import 'ble/utils/SPUtils.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SPUtils.init();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _ledBtJlOtaPlugin = LedBtJlOta.instance;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _ledBtJlOtaPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
if (Platform.isAndroid) {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent, // 设置透明状态栏
statusBarBrightness: Brightness.dark, // 设置状态栏文本颜色,基于亮度
systemNavigationBarColor: Colors.grey, // 设置底部导航栏颜色
statusBarIconBrightness: Brightness.dark, // 可选,直接设置状态栏文本颜色
),
);
} else {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemStatusBarContrastEnforced: true,
// Enforce contrast for status bar text and icons
statusBarColor: Colors.transparent, // Make the status bar transparent
),
);
}
}
@override
Widget build(BuildContext context) {
return OKToast(
child: MaterialApp(
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
debugShowCheckedModeBanner: false,
home: const HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: [
ElevatedButton(
onPressed: () async {
bool flag = await PermissionUtil.instance
.checkPermission(context);
if (flag) {
Navigator.of(context).push(
CupertinoPageRoute(builder: (BuildContext context) {
return const BleDevicePage();
}));
}
//ConnectUtil.instance.start();
},
child: Text("连接"))
],
),
),
),
);
}
}