|
@@ -1,4 +1,3 @@
|
|
-import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
import 'dart:convert';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
@@ -22,21 +21,35 @@ class MyApp extends StatelessWidget {
|
|
return ScreenUtilInit(
|
|
return ScreenUtilInit(
|
|
builder: (BuildContext context, Widget? child) {
|
|
builder: (BuildContext context, Widget? child) {
|
|
return MaterialApp(
|
|
return MaterialApp(
|
|
- title: 'SmartLEDZ WiFi Test',
|
|
|
|
|
|
+ title: 'FX430 WIFI测试',
|
|
theme: ThemeData(
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
),
|
|
home: Scaffold(
|
|
home: Scaffold(
|
|
- body: child!,
|
|
|
|
|
|
+ body: Column(
|
|
|
|
+ children: [
|
|
|
|
+ Container(
|
|
|
|
+ color: Colors.blue,
|
|
|
|
+ alignment: Alignment.center,
|
|
|
|
+ child: SafeArea(
|
|
|
|
+ left: false,
|
|
|
|
+ right: false,
|
|
|
|
+ bottom: false,
|
|
|
|
+ child: Container(
|
|
|
|
+ alignment: Alignment.center,
|
|
|
|
+ height: 50.h,
|
|
|
|
+ child: Text("FX430 WIFI测试", style: TextStyle(color: Colors.white, fontSize: 20.sp)),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ const Expanded(
|
|
|
|
+ child: WifiList(),
|
|
|
|
+ )
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
},
|
|
},
|
|
- child: const SafeArea(
|
|
|
|
- left: false,
|
|
|
|
- right: false,
|
|
|
|
- bottom: false,
|
|
|
|
- child: WifiList(),
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -52,7 +65,6 @@ class _WifiListState extends State<WifiList> {
|
|
|
|
|
|
final List<WifiModel> _wifiList = []; // 扫描的wifi列表
|
|
final List<WifiModel> _wifiList = []; // 扫描的wifi列表
|
|
final List<String> _selectWifiList = []; // 已选择的wifi的bssid标识列表
|
|
final List<String> _selectWifiList = []; // 已选择的wifi的bssid标识列表
|
|
- late bool testing = false; // 是否测试中:false[否]、true[是]
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
@@ -65,6 +77,9 @@ class _WifiListState extends State<WifiList> {
|
|
switch(jsonArr["cmd"]){
|
|
switch(jsonArr["cmd"]){
|
|
case "scanResult": // 扫描
|
|
case "scanResult": // 扫描
|
|
setState(() {
|
|
setState(() {
|
|
|
|
+ for (var element in _wifiList) { // 已存在则跳过
|
|
|
|
+ if(element.bssid == jsonArr["bssid"]) return;
|
|
|
|
+ }
|
|
_wifiList.add(WifiModel(
|
|
_wifiList.add(WifiModel(
|
|
ssid: jsonArr["ssid"],
|
|
ssid: jsonArr["ssid"],
|
|
bssid: jsonArr["bssid"],
|
|
bssid: jsonArr["bssid"],
|
|
@@ -87,16 +102,15 @@ class _WifiListState extends State<WifiList> {
|
|
});
|
|
});
|
|
|
|
|
|
startScanWifi();
|
|
startScanWifi();
|
|
- Timer.periodic(const Duration(seconds: 3), (timer) {
|
|
|
|
- if(testing) return; // 测试中,忽略定时扫描
|
|
|
|
- startScanWifi(); // 定时调用扫描方法
|
|
|
|
- });
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// 扫描wifi
|
|
// 扫描wifi
|
|
- void startScanWifi(){
|
|
|
|
|
|
+ void startScanWifi([void Function()? callback]){
|
|
_wifiList.clear();
|
|
_wifiList.clear();
|
|
WiFiPlugin.startScan();
|
|
WiFiPlugin.startScan();
|
|
|
|
+ Future.delayed(const Duration(seconds: 3), (){
|
|
|
|
+ callback?.call();
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
// 开始测试
|
|
// 开始测试
|
|
@@ -106,7 +120,6 @@ class _WifiListState extends State<WifiList> {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- testing = true; // 置为测试状态
|
|
|
|
if(_selectWifiList.isNotEmpty){ // 有选中的wifi,则只处理选中的wifi
|
|
if(_selectWifiList.isNotEmpty){ // 有选中的wifi,则只处理选中的wifi
|
|
eachTestWifiList(true);
|
|
eachTestWifiList(true);
|
|
return;
|
|
return;
|
|
@@ -121,7 +134,6 @@ class _WifiListState extends State<WifiList> {
|
|
int wifiIndex = index;
|
|
int wifiIndex = index;
|
|
if(isSelect == true){ // 处理选中设备
|
|
if(isSelect == true){ // 处理选中设备
|
|
if(index >= _selectWifiList.length){ // 处理完成
|
|
if(index >= _selectWifiList.length){ // 处理完成
|
|
- testing = false;
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
for(int i=0; i<_wifiList.length; i++){
|
|
for(int i=0; i<_wifiList.length; i++){
|
|
@@ -132,7 +144,6 @@ class _WifiListState extends State<WifiList> {
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
if(index >= _wifiList.length){ // 处理完成
|
|
if(index >= _wifiList.length){ // 处理完成
|
|
- testing = false;
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -142,7 +153,6 @@ class _WifiListState extends State<WifiList> {
|
|
setState(()=>_wifiList[wifiIndex].result="正在测试");
|
|
setState(()=>_wifiList[wifiIndex].result="正在测试");
|
|
debugPrint("开始连接wifi ssid --> ${wifiModel.ssid} bssid --> ${wifiModel.bssid}");
|
|
debugPrint("开始连接wifi ssid --> ${wifiModel.ssid} bssid --> ${wifiModel.bssid}");
|
|
WiFiPlugin.connect(wifiModel.ssid, wifiModel.bssid, "12345678");
|
|
WiFiPlugin.connect(wifiModel.ssid, wifiModel.bssid, "12345678");
|
|
- testing = false; // TODO developer,置为非测试状态
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -151,6 +161,7 @@ class _WifiListState extends State<WifiList> {
|
|
children: [
|
|
children: [
|
|
Expanded(
|
|
Expanded(
|
|
child: ListView(
|
|
child: ListView(
|
|
|
|
+ padding: EdgeInsets.zero,
|
|
children: List.generate(_wifiList.length, (index){
|
|
children: List.generate(_wifiList.length, (index){
|
|
WifiModel wifi = _wifiList[index];
|
|
WifiModel wifi = _wifiList[index];
|
|
return WifiItem(
|
|
return WifiItem(
|
|
@@ -169,13 +180,32 @@ class _WifiListState extends State<WifiList> {
|
|
}),
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
- ButtonForBlock(
|
|
|
|
- title: "开始测试",
|
|
|
|
- fontSize: 20.sp,
|
|
|
|
- radius: 0,
|
|
|
|
- width: MediaQuery.of(context).size.width,
|
|
|
|
- height: 55.sp,
|
|
|
|
- onTap: startTest,
|
|
|
|
|
|
+ Row(
|
|
|
|
+ children: [
|
|
|
|
+ ButtonForBlock(
|
|
|
|
+ title: "刷新列表",
|
|
|
|
+ fontSize: 20.sp,
|
|
|
|
+ radius: 0,
|
|
|
|
+ bgColor: const Color(0xFFFFAA00),
|
|
|
|
+ activeBgColor: const Color(0xFFAA8800),
|
|
|
|
+ width: MediaQuery.of(context).size.width/2,
|
|
|
|
+ height: 55.sp,
|
|
|
|
+ onTap: (){
|
|
|
|
+ Modal.openLoading(context: context, tip: "正在扫描wifi");
|
|
|
|
+ startScanWifi((){
|
|
|
|
+ Navigator.pop(context);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ButtonForBlock(
|
|
|
|
+ title: "开始测试",
|
|
|
|
+ fontSize: 20.sp,
|
|
|
|
+ radius: 0,
|
|
|
|
+ width: MediaQuery.of(context).size.width/2,
|
|
|
|
+ height: 55.sp,
|
|
|
|
+ onTap: startTest,
|
|
|
|
+ )
|
|
|
|
+ ],
|
|
)
|
|
)
|
|
],
|
|
],
|
|
);
|
|
);
|