wifi_item.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:smartledz_wifi_test/models/wifi_model.dart';
  4. class WifiItem extends StatefulWidget {
  5. final WifiModel wifiModel; // wifi模型
  6. final bool active; // 是否选中
  7. final Function(WifiModel wifiModel)? onTap; // 是否选中
  8. const WifiItem({
  9. super.key,
  10. required this.wifiModel,
  11. this.active = false,
  12. this.onTap,
  13. });
  14. @override
  15. State<WifiItem> createState() => _WifiItemState();
  16. }
  17. class _WifiItemState extends State<WifiItem> {
  18. // 测试结果与颜色的对应关系
  19. final Map<String, Color> resultAsColor = {
  20. "未测试": Colors.grey,
  21. "正在测试": Colors.blue,
  22. "测试通过": Colors.green,
  23. "未通过": Colors.red,
  24. };
  25. @override
  26. Widget build(BuildContext context) {
  27. double borderWidth = .7.sp; // 边框宽度
  28. Color resultColor = Colors.grey; // 测试结果文本颜色
  29. if(resultAsColor.containsKey(widget.wifiModel.result)){
  30. resultColor = resultAsColor[widget.wifiModel.result]!;
  31. }
  32. return GestureDetector(
  33. onTap: ()=>widget.onTap?.call(widget.wifiModel),
  34. child: Container(
  35. height: 50.sp,
  36. decoration: BoxDecoration(
  37. color: widget.active? Colors.pink.shade100: null,
  38. border: Border(
  39. bottom: BorderSide(color: Colors.grey, width: borderWidth)
  40. )
  41. ),
  42. child: Row(
  43. children: [
  44. Expanded(
  45. child: Container(
  46. alignment: Alignment.centerLeft,
  47. padding: EdgeInsets.symmetric(horizontal: 5.sp),
  48. child: Text(widget.wifiModel.ssid, style: TextStyle(fontSize: 18.sp)),
  49. ),
  50. ),
  51. Container(
  52. alignment: Alignment.center,
  53. width: 50.w,
  54. decoration: BoxDecoration(
  55. border: Border.symmetric(vertical: BorderSide(color: Colors.grey, width: borderWidth))
  56. ),
  57. child: Text(widget.wifiModel.rssi.toString(), style: TextStyle(fontSize: 14.sp, color: Colors.green)),
  58. ),
  59. Container(
  60. alignment: Alignment.center,
  61. width: 80.w,
  62. child: Text(widget.wifiModel.result, style: TextStyle(fontSize: 14.sp, color: resultColor)),
  63. ),
  64. ],
  65. ),
  66. ),
  67. );
  68. }
  69. }