Flutter易用控件集合插件helios_easycontrols的使用
Flutter易用控件集合插件helios_easycontrols的使用
通过helios_easycontrols
插件,您可以轻松读取和设置Helios KWL设备上的状态。该插件支持easyControls 3.0(HTTP接口)。
特性
- 读取当前送风和排风百分比及转速。
- 设置目标送风和排风百分比。
额外信息
该插件使用无头Chrome(通过package:puppeteer
)来访问设备。
目前建议不要频繁访问设备,因为这可能会使KWL服务器过载并导致设备“冻结”。每15到30分钟访问一次似乎较为合适。
欢迎贡献以改进此插件!
完整示例代码
以下是一个完整的示例代码,展示了如何使用helios_easycontrols
插件读取和设置设备的状态:
import 'package:flutter/material.dart';
import 'package:helios_easycontrols/helios_easycontrols.dart'; // 导入helios_easycontrols插件
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
[@override](/user/override)
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final HeliosEasyControls _heliosEasyControls = HeliosEasyControls(); // 创建HeliosEasyControls实例
String _status = ""; // 存储设备状态的变量
double _supplyAirPercent = 0; // 存储送风百分比的变量
double _extractAirPercent = 0; // 存储排风百分比的变量
[@override](/user/override)
void initState() {
super.initState();
// 在初始化时读取设备状态
readDeviceStatus();
}
Future<void> readDeviceStatus() async {
try {
// 读取送风和排风百分比及转速
final status = await _heliosEasyControls.readStatus();
setState(() {
_status = status;
_supplyAirPercent = status.supplyAirPercent;
_extractAirPercent = status.extractAirPercent;
});
} catch (e) {
setState(() {
_status = "Error reading status: $e";
});
}
}
Future<void> setDeviceTarget() async {
try {
// 设置目标送风和排风百分比
await _heliosEasyControls.setTargetSupplyAirPercent(70); // 设置送风百分比为70%
await _heliosEasyControls.setTargetExtractAirPercent(30); // 设置排风百分比为30%
setState(() {
_status = "Target settings updated successfully.";
});
} catch (e) {
setState(() {
_status = "Error setting targets: $e";
});
}
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Helios EasyControls Demo"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Status: $_status", style: TextStyle(fontSize: 18)),
SizedBox(height: 20),
Text("Supply Air Percent: $_supplyAirPercent%", style: TextStyle(fontSize: 18)),
Text("Extract Air Percent: $_extractAirPercent%", style: TextStyle(fontSize: 18)),
SizedBox(height: 20),
ElevatedButton(
onPressed: () => setDeviceTarget(),
child: Text("Set Target Percentages"),
),
],
),
),
);
}
}
更多关于Flutter易用控件集合插件helios_easycontrols的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter易用控件集合插件helios_easycontrols的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
helios_easycontrols
是一个 Flutter 插件,旨在提供一系列易用的控件,帮助开发者快速构建美观且功能丰富的 Flutter 应用。这个插件可能包含了一些常用的 UI 组件、动画效果、布局工具等,以简化开发流程并提高代码的可维护性。
安装步骤
-
在
pubspec.yaml
中添加依赖: 打开你的 Flutter 项目的pubspec.yaml
文件,在dependencies
部分添加helios_easycontrols
依赖项。dependencies: flutter: sdk: flutter helios_easycontrols: ^版本号
请将
^版本号
替换为最新的版本号。你可以在 pub.dev 上查找最新的版本。 -
运行
flutter pub get
: 在终端中运行以下命令以获取依赖包。flutter pub get
-
导入包: 在你的 Dart 文件中导入
helios_easycontrols
包。import 'package:helios_easycontrols/helios_easycontrols.dart';
使用示例
以下是一些可能包含在 helios_easycontrols
中的控件及其使用示例:
1. 自定义按钮
EasyButton(
text: 'Click Me',
onPressed: () {
print('Button Pressed!');
},
color: Colors.blue,
textColor: Colors.white,
);
2. 自定义卡片
EasyCard(
child: Column(
children: [
Text('Card Title', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Text('This is a custom card widget provided by helios_easycontrols.'),
],
),
elevation: 5,
borderRadius: BorderRadius.circular(10),
);
3. 自定义加载指示器
EasyLoadingIndicator(
size: 50,
color: Colors.blue,
);
4. 自定义对话框
EasyDialog(
title: 'Alert',
content: 'This is a custom dialog widget.',
actions: [
EasyButton(
text: 'OK',
onPressed: () {
Navigator.pop(context);
},
),
],
);
5. 自定义输入框
EasyTextField(
hintText: 'Enter your name',
onChanged: (value) {
print('Input: $value');
},
);