lx_ota 0.0.1 copy "lx_ota: ^0.0.1" to clipboard
lx_ota: ^0.0.1 copied to clipboard

lx_recordBle OTA update.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:lx_ota/lx_ota.dart';
import 'package:lx_ota/sn_filePath_tool.dart';
import 'package:lx_ota_example/permission_util.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  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 _lxOtaPlugin = LxOta();

  @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 _lxOtaPlugin.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;

    PermissionUtil.preRequestPermissions([
      Permission.location,
      Permission.bluetoothScan,
      Permission.bluetoothConnect,
      Permission.bluetoothAdvertise
    ], onAllowed: (result) async {
      sn_testFirmwareUpgrade();
    });

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  void sn_testFirmwareUpgrade() async {
    if (Platform.isIOS) {
      try {
        String testOTA = await sn_moveFileToLib();
        _lxOtaPlugin.firmwareUpdate(
            testOTA,
            "701DF182-C248-E15C-EF0F-73F4F939BD1D",
            "DELI_MP306W_921725", (int result) {
          print("sn_log example 收到进度 ==>>> ${result}%");
        });
      } catch (e) {
        print("firmwareUpdate e=> ${e}");
      }
    } else {
      try {
        String testOTA = await sn_moveFileToLib();
        _lxOtaPlugin.firmwareUpdate(
            testOTA, "41:42:9F:D9:19:E5", "DELI_MP306W_921725", (int result) {
          print("!!!! test ==>>> ${result}%");
        });
      } catch (e) {
        print("firmwareUpdate e=> ${e}");
      }
    }
  }

  /// 调试用
  static sn_moveFileToLib() async {
    // String filePath = 'audio/zlftest001.opus';
    // String _fileName = 'zlftest001.opus';

    String _fileName = '0202.fot';
    // String _fileName = 'fw5000.fot';

    String filePath = 'audio/${_fileName}';
    final ByteData data = await rootBundle.load(filePath);
    final List<int> bytes =
        data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    String _filePath = await SNFilePathTool.sn_getFilePath(_fileName);
    File file = File(_filePath);
    await file.writeAsBytes(bytes);
    print("该文件bytes大小为 ${bytes.length}");
    return _filePath;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}
0
likes
130
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

lx_recordBle OTA update.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path_provider, plugin_platform_interface

More

Packages that depend on lx_ota

Packages that implement lx_ota