12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:smartledz_wifi_test/models/wifi_model.dart';
- class WifiItem extends StatefulWidget {
- final WifiModel wifiModel; // wifi模型
- final bool active; // 是否选中
- final Function(WifiModel wifiModel)? onTap; // 是否选中
- const WifiItem({
- super.key,
- required this.wifiModel,
- this.active = false,
- this.onTap,
- });
- @override
- State<WifiItem> createState() => _WifiItemState();
- }
- class _WifiItemState extends State<WifiItem> {
- // 测试结果与颜色的对应关系
- final Map<String, Color> resultAsColor = {
- "未测试": Colors.grey,
- "正在测试": Colors.blue,
- "测试通过": Colors.green,
- "未通过": Colors.red,
- };
- @override
- Widget build(BuildContext context) {
- Color resultColor = Colors.grey;
- if(resultAsColor.containsKey(widget.wifiModel.result)){
- resultColor = resultAsColor[widget.wifiModel.result]!;
- }
- return GestureDetector(
- onTap: ()=>widget.onTap?.call(widget.wifiModel),
- child: Container(
- height: 40.sp,
- decoration: BoxDecoration(
- color: widget.active? Colors.pink.shade100: null,
- border: Border(
- bottom: BorderSide(color: Colors.grey, width: .5.sp)
- )
- ),
- child: Row(
- children: [
- Expanded(
- child: Container(
- alignment: Alignment.centerLeft,
- padding: EdgeInsets.symmetric(horizontal: 5.sp),
- child: Text(widget.wifiModel.ssid, style: TextStyle(fontSize: 16.sp)),
- ),
- ),
- Container(
- alignment: Alignment.center,
- width: 50.w,
- decoration: BoxDecoration(
- border: Border.symmetric(vertical: BorderSide(color: Colors.grey, width: .5.sp))
- ),
- child: Text(widget.wifiModel.rssi.toString(), style: TextStyle(fontSize: 14.sp, color: Colors.green)),
- ),
- Container(
- alignment: Alignment.center,
- width: 80.w,
- child: Text(widget.wifiModel.result, style: TextStyle(fontSize: 14.sp, color: resultColor)),
- ),
- ],
- ),
- ),
- );
- }
- }
|