linfeng 1 年之前
父节点
当前提交
4a37b9fce7
共有 3 个文件被更改,包括 60 次插入28 次删除
  1. 1 1
      android/app/src/main/AndroidManifest.xml
  2. 56 26
      lib/main.dart
  3. 3 1
      lib/widgets/button_for_block.dart

+ 1 - 1
android/app/src/main/AndroidManifest.xml

@@ -7,7 +7,7 @@
     <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
 
     <application
-        android:label="smartledz_wifi_test"
+        android:label="FX430 WIFI测试"
         android:name="${applicationName}"
         android:icon="@mipmap/ic_launcher">
         <activity

+ 56 - 26
lib/main.dart

@@ -1,4 +1,3 @@
-import 'dart:async';
 import 'dart:convert';
 
 import 'package:flutter/material.dart';
@@ -22,21 +21,35 @@ class MyApp extends StatelessWidget {
     return ScreenUtilInit(
       builder: (BuildContext context, Widget? child) {
         return MaterialApp(
-          title: 'SmartLEDZ WiFi Test',
+          title: 'FX430 WIFI测试',
           theme: ThemeData(
             primarySwatch: Colors.blue,
           ),
           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<String> _selectWifiList = []; // 已选择的wifi的bssid标识列表
-  late bool testing = false; // 是否测试中:false[否]、true[是]
 
   @override
   void initState() {
@@ -65,6 +77,9 @@ class _WifiListState extends State<WifiList> {
       switch(jsonArr["cmd"]){
         case "scanResult": // 扫描
           setState(() {
+            for (var element in _wifiList) { // 已存在则跳过
+              if(element.bssid == jsonArr["bssid"]) return;
+            }
             _wifiList.add(WifiModel(
                 ssid: jsonArr["ssid"],
                 bssid: jsonArr["bssid"],
@@ -87,16 +102,15 @@ class _WifiListState extends State<WifiList> {
     });
 
     startScanWifi();
-    Timer.periodic(const Duration(seconds: 3), (timer) {
-      if(testing) return; // 测试中,忽略定时扫描
-      startScanWifi(); // 定时调用扫描方法
-    });
   }
 
   // 扫描wifi
-  void startScanWifi(){
+  void startScanWifi([void Function()? callback]){
     _wifiList.clear();
     WiFiPlugin.startScan();
+    Future.delayed(const Duration(seconds: 3), (){
+      callback?.call();
+    });
   }
 
   // 开始测试
@@ -106,7 +120,6 @@ class _WifiListState extends State<WifiList> {
       return;
     }
 
-    testing = true; // 置为测试状态
     if(_selectWifiList.isNotEmpty){ // 有选中的wifi,则只处理选中的wifi
       eachTestWifiList(true);
       return;
@@ -121,7 +134,6 @@ class _WifiListState extends State<WifiList> {
     int wifiIndex = index;
     if(isSelect == true){ // 处理选中设备
       if(index >= _selectWifiList.length){ // 处理完成
-        testing = false;
         return;
       }
       for(int i=0; i<_wifiList.length; i++){
@@ -132,7 +144,6 @@ class _WifiListState extends State<WifiList> {
       }
     }else{
       if(index >= _wifiList.length){ // 处理完成
-        testing = false;
         return;
       }
     }
@@ -142,7 +153,6 @@ class _WifiListState extends State<WifiList> {
     setState(()=>_wifiList[wifiIndex].result="正在测试");
     debugPrint("开始连接wifi  ssid --> ${wifiModel.ssid}   bssid --> ${wifiModel.bssid}");
     WiFiPlugin.connect(wifiModel.ssid, wifiModel.bssid, "12345678");
-    testing = false; // TODO developer,置为非测试状态
   }
 
   @override
@@ -151,6 +161,7 @@ class _WifiListState extends State<WifiList> {
       children: [
         Expanded(
           child: ListView(
+            padding: EdgeInsets.zero,
             children: List.generate(_wifiList.length, (index){
               WifiModel wifi = _wifiList[index];
               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,
+            )
+          ],
         )
       ],
     );

+ 3 - 1
lib/widgets/button_for_block.dart

@@ -8,6 +8,7 @@ class ButtonForBlock extends StatefulWidget {
   final void Function()? onTap;
   final double? fontSize;
   final Color? bgColor;
+  final Color? activeBgColor;
   final BoxBorder? border;
   final double? radius;
 
@@ -19,6 +20,7 @@ class ButtonForBlock extends StatefulWidget {
     this.height,
     this.fontSize,
     this.bgColor=const Color(0xFF00aaFF),
+    this.activeBgColor=const Color(0xff007ab6),
     this.border,
     this.radius,
   }) : super(key: key);
@@ -42,7 +44,7 @@ class _ButtonForBlockState extends State<ButtonForBlock> {
         alignment: Alignment.center,
         width: widget.width ?? 280.w,
         decoration: BoxDecoration(
-          color: isOn? const Color(0xff007ab6): widget.bgColor,
+          color: isOn? widget.activeBgColor: widget.bgColor,
           borderRadius: BorderRadius.circular(widget.radius ?? (widget.height != null? widget.height!/2: 35.h/2)),
           border: widget.border
         ),