195 lines
5.8 KiB
Dart
195 lines
5.8 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:qhd_prevention/customWidget/custom_button.dart';
|
||
|
import 'package:qhd_prevention/customWidget/custom_driver_drawer.dart';
|
||
|
import 'package:qhd_prevention/pages/home/risk/risk_detail_page.dart';
|
||
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
||
|
import 'package:qhd_prevention/tools/tools.dart';
|
||
|
import '/customWidget/search_bar_widget.dart';
|
||
|
|
||
|
class RiskControlPage extends StatefulWidget {
|
||
|
const RiskControlPage({super.key});
|
||
|
|
||
|
@override
|
||
|
State<RiskControlPage> createState() => _RiskControlPageState();
|
||
|
}
|
||
|
|
||
|
class _RiskControlPageState extends State<RiskControlPage> {
|
||
|
// 模拟数据
|
||
|
final List<Map<String, dynamic>> _dataInfos = List.generate(10, (i) {
|
||
|
bool read = i % 3 == 0;
|
||
|
return {
|
||
|
'title': '测试数据标题标题 ${i + 1}',
|
||
|
'label1': '2025-06-${10 + i} 12:3${i}',
|
||
|
'label2': '2025-06-${1 + i} 2:1${i}',
|
||
|
'level': getRandomWithNum(1, 4),
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// 风险等级颜色
|
||
|
final List<Color> _fxColors = [
|
||
|
const Color(0xFFFADBD9),
|
||
|
const Color(0xFFFCE6D2),
|
||
|
const Color(0xFFFDF2CE),
|
||
|
const Color(0xFFCCE6FF),
|
||
|
];
|
||
|
final TextEditingController _searchController = TextEditingController();
|
||
|
|
||
|
// 风险等级文本
|
||
|
final List<String> _levelTexts = ["重大风险/A级", "较大风险/B级", "一般风险/C级", "低风险/D级"];
|
||
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
// 取屏幕宽度
|
||
|
final double screenWidth = MediaQuery.of(context).size.width;
|
||
|
|
||
|
return Scaffold(
|
||
|
key: _scaffoldKey, // ② 绑定 key
|
||
|
appBar: MyAppbar(
|
||
|
title: "风险分布",
|
||
|
actions: [
|
||
|
TextButton(
|
||
|
onPressed: () {
|
||
|
// 查询 右侧弹窗页面
|
||
|
_scaffoldKey.currentState?.openEndDrawer();
|
||
|
},
|
||
|
child: Text(
|
||
|
"查询",
|
||
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
endDrawer: Drawer(
|
||
|
// 用 Container 限制宽度为屏幕的 3/5
|
||
|
child: Container(
|
||
|
width: screenWidth * 3 / 5,
|
||
|
color: Colors.white,
|
||
|
child: const CustomDriverDrawer(),
|
||
|
),
|
||
|
),
|
||
|
body: SafeArea(child: _vcDetailWidget()),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget _vcDetailWidget() {
|
||
|
return Column(
|
||
|
children: [
|
||
|
Padding(
|
||
|
padding: EdgeInsets.all(10),
|
||
|
child: SearchBarWidget(
|
||
|
controller: _searchController,
|
||
|
onSearch: (keyboard) {
|
||
|
// 输入请求接口
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
|
||
|
Expanded(
|
||
|
child: ListView.separated(
|
||
|
separatorBuilder: (_, __) => const Divider(height: 1),
|
||
|
itemCount: _dataInfos.length,
|
||
|
itemBuilder: (context, index) {
|
||
|
final item = _dataInfos[index];
|
||
|
return _fxitemCell(item);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget _fxitemCell(final item) {
|
||
|
int level = item['level'] as int;
|
||
|
// 确保level在有效范围内 (1-4)
|
||
|
level = level.clamp(1, 4) - 1;
|
||
|
|
||
|
// 使用GestureDetector包裹整个列表项以添加点击事件
|
||
|
return GestureDetector(
|
||
|
onTap: () {
|
||
|
// 点击后跳转到详情页面
|
||
|
Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
|
builder: (context) => RiskDetailPage(itemData: item),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
child: Container(
|
||
|
height: 100,
|
||
|
color: Colors.white,
|
||
|
padding: EdgeInsets.symmetric(horizontal: 16), // 添加水平内边距
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
children: [
|
||
|
// 左侧信息列
|
||
|
Expanded(
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
item['title'] ?? '',
|
||
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||
|
maxLines: 1,
|
||
|
overflow: TextOverflow.ellipsis,
|
||
|
),
|
||
|
SizedBox(height: 8),
|
||
|
Text(
|
||
|
item['label1'] ?? '',
|
||
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||
|
),
|
||
|
SizedBox(height: 4),
|
||
|
Text(
|
||
|
item['label2'] ?? '',
|
||
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
|
||
|
// 右侧风险等级和箭头
|
||
|
Padding(
|
||
|
padding: EdgeInsets.only(top: 15),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
// 风险等级标签
|
||
|
Row(
|
||
|
children: [
|
||
|
Container(
|
||
|
padding: EdgeInsets.symmetric(
|
||
|
horizontal: 8,
|
||
|
vertical: 4,
|
||
|
),
|
||
|
decoration: BoxDecoration(
|
||
|
color: _fxColors[level],
|
||
|
borderRadius: BorderRadius.circular(2),
|
||
|
),
|
||
|
child: Text(
|
||
|
_levelTexts[level],
|
||
|
style: TextStyle(fontSize: 12),
|
||
|
),
|
||
|
),
|
||
|
SizedBox(width: 30),
|
||
|
],
|
||
|
),
|
||
|
SizedBox(height: 12), // 添加间距
|
||
|
Row(
|
||
|
children: [
|
||
|
SizedBox(width: 110),
|
||
|
Icon(Icons.arrow_forward_ios_rounded, size: 16),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|