Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
matteriot committed Sep 22, 2023
1 parent 919e4fb commit 0ad63c7
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 168 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<application
android:label="@string/app_name"
android:name="${applicationName}"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher"
tools:replace="android:label">
<activity
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: "OpenIoTHub",
theme: CustomThemes.light,
darkTheme: CustomThemes.dark,
Expand Down
29 changes: 15 additions & 14 deletions lib/pages/commonDevice/commonDeviceListPage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:openiothub/model/custom_theme.dart';
Expand Down Expand Up @@ -31,7 +32,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
void initState() {
super.initState();
getAllCommonDevice();
_timerPeriod = Timer.periodic(Duration(seconds: 3), (Timer timer) {
_timerPeriod = Timer.periodic(const Duration(seconds: 5), (Timer timer) {
getAllCommonDevice();
});
print("init common devie List");
Expand All @@ -40,9 +41,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
@override
void dispose() {
super.dispose();
if (_timerPeriod != null) {
_timerPeriod.cancel();
}
_timerPeriod.cancel();
}

@override
Expand Down Expand Up @@ -80,7 +79,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(
icon: const Icon(
Icons.refresh,
color: Colors.white,
),
Expand All @@ -90,7 +89,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
});
}),
IconButton(
icon: Icon(
icon: const Icon(
Icons.add_circle,
color: Colors.white,
),
Expand All @@ -99,7 +98,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
}),
],
),
body: divided.length > 0
body: divided.isNotEmpty
? ListView(children: divided)
: Container(
child: Column(children: [
Expand All @@ -109,7 +108,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
TextButton(
style: ButtonStyle(
side: MaterialStateProperty.all(
BorderSide(color: Colors.grey, width: 1)),
const BorderSide(color: Colors.grey, width: 1)),
shape: MaterialStateProperty.all(StadiumBorder()),
),
onPressed: () {
Expand All @@ -134,15 +133,15 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
children: <Widget>[
TextFormField(
controller: _description_controller,
decoration: InputDecoration(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(10.0),
labelText: '备注',
helperText: '自定义备注',
),
),
TextFormField(
controller: _remote_ip_controller,
decoration: InputDecoration(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(10.0),
labelText: '远程内网的IP',
helperText: '内网设备的IP',
Expand Down Expand Up @@ -222,7 +221,9 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
_CommonDeviceList = response.devices;
});
} catch (e) {
print("openiothub获取设备失败:$e");
if (kDebugMode) {
print("openiothub获取设备失败:$e");
}
// Fluttertoast.showToast(msg: "获取设备列表失败:${e}");
}
}
Expand All @@ -235,7 +236,7 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
padding: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 15.0),
child: Row(
children: <Widget>[
Icon(Icons.cloud_done),
const Icon(Icons.cloud_done),
Expanded(
child: Text(
"${pair.name}(${pair.description})",
Expand All @@ -262,13 +263,13 @@ class _CommonDeviceListPageState extends State<CommonDeviceListPage> {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("选择一个内网:"),
title: const Text("选择一个内网:"),
content: ListView(
children: divided,
),
actions: <Widget>[
TextButton(
child: Text("取消"),
child: const Text("取消"),
onPressed: () {
Navigator.of(context).pop();
},
Expand Down
42 changes: 21 additions & 21 deletions lib/pages/commonDevice/commonDeviceServiceTypesList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ class _CommonDeviceServiceTypesListState
if (item is String) {
switch (item) {
case TAG_START:
return Divider(
return const Divider(
height: 1.0,
);
break;
case TAG_END:
return Divider(
return const Divider(
height: 1.0,
);
break;
case TAG_CENTER:
return Padding(
padding: const EdgeInsets.fromLTRB(50.0, 0.0, 0.0, 0.0),
return const Padding(
padding: EdgeInsets.fromLTRB(50.0, 0.0, 0.0, 0.0),
child: Divider(
height: 1.0,
),
Expand Down Expand Up @@ -171,9 +171,9 @@ class _CommonDeviceServiceTypesListState
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("服务"), actions: <Widget>[
appBar: AppBar(title: const Text("服务"), actions: <Widget>[
IconButton(
icon: Icon(
icon: const Icon(
Icons.delete,
color: Colors.red,
),
Expand All @@ -182,7 +182,7 @@ class _CommonDeviceServiceTypesListState
_deleteCurrentDevice();
}),
IconButton(
icon: Icon(
icon: const Icon(
Icons.power_settings_new,
color: Colors.white,
),
Expand All @@ -192,7 +192,7 @@ class _CommonDeviceServiceTypesListState
}),
// TODO 设备的详情
IconButton(
icon: Icon(
icon: const Icon(
Icons.info,
color: Colors.white,
),
Expand All @@ -214,11 +214,11 @@ class _CommonDeviceServiceTypesListState
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("删除设备"),
content: Text("确认删除此设备?"),
title: const Text("删除设备"),
content: const Text("确认删除此设备?"),
actions: <Widget>[
TextButton(
child: Text("取消"),
child: const Text("取消"),
onPressed: () {
Navigator.of(context).pop();
},
Expand All @@ -244,25 +244,25 @@ class _CommonDeviceServiceTypesListState
return showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("唤醒设备"),
content: Text("第一次使用请选择\'设置物理地址\',设置过物理地址可以直接点击\'唤醒设备\'。"),
title: const Text("唤醒设备"),
content: const Text("第一次使用请选择\'设置物理地址\',设置过物理地址可以直接点击\'唤醒设备\'。"),
actions: <Widget>[
TextButton(
child: Text("取消"),
child: const Text("取消"),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text("重设物理地址"),
child: const Text("重设物理地址"),
onPressed: () {
_setMacAddr().then((_) {
Navigator.of(context).pop();
});
},
),
TextButton(
child: Text("唤醒设备"),
child: const Text("唤醒设备"),
onPressed: () {
CommonDeviceApi.wakeOnLAN(widget.device).then((_) {
Navigator.of(context).pop();
Expand All @@ -274,7 +274,7 @@ class _CommonDeviceServiceTypesListState

Future _setMacAddr() async {
TextEditingController _mac_controller = TextEditingController.fromValue(
TextEditingValue(text: "54-07-2F-BB-BB-2F"));
const TextEditingValue(text: "54-07-2F-BB-BB-2F"));
return showDialog(
context: context,
builder: (_) => AlertDialog(
Expand All @@ -283,7 +283,7 @@ class _CommonDeviceServiceTypesListState
children: <Widget>[
TextFormField(
controller: _mac_controller,
decoration: InputDecoration(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(10.0),
labelText: '物理地址',
helperText: '机器有线网卡的物理地址',
Expand All @@ -293,13 +293,13 @@ class _CommonDeviceServiceTypesListState
),
actions: <Widget>[
TextButton(
child: Text("取消"),
child: const Text("取消"),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text("设置"),
child: const Text("设置"),
onPressed: () {
var device = widget.device;
device.mac = _mac_controller.text;
Expand Down Expand Up @@ -338,7 +338,7 @@ class _CommonDeviceServiceTypesListState

return Scaffold(
appBar: AppBar(
title: Text('设备详情'),
title: const Text('设备详情'),
),
body: ListView(children: divided),
);
Expand Down
Loading

0 comments on commit 0ad63c7

Please sign in to comment.