flutter_integrated_whb/lib/pages/home/low_page.dart

113 lines
2.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/tools.dart';
import '../../http/ApiService.dart';
import '/customWidget/search_bar_widget.dart';
class LowPage extends StatefulWidget {
const LowPage({super.key});
@override
State<LowPage> createState() => _LowPagePageState();
}
class _LowPagePageState extends State<LowPage> {
// 模拟数据
final List<Map<String, dynamic>> _dataInfos = List.generate(10, (i) {
return {
'title': '测试数据标题标题 ${i + 1}',
};
});
final TextEditingController _searchController = TextEditingController();
String treeJson="";
@override
void initState() {
// TODO: implement initState
super.initState();
_getLowList();
}
Future<void> _getLowList() async {
try {
final result = await ApiService.getHiddenTreatmentListTree();
if (result['result'] == 'success') {
setState(() {
treeJson= result['zTreeNodes'];
});
}else{
_showMessage('加载数据失败');
}
} catch (e) {
// 出错时可以 Toast 或者在页面上显示错误状态
print('加载数据失败:$e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppbar(
title: "法律法规",
),
body: SafeArea(
child: _vcDetailWidget()
),
);
}
Widget _vcDetailWidget() {
return Column(
children: [
Padding(
padding: EdgeInsets.all(10),
child: SearchBarWidget(
controller: _searchController,
onSearch: (keyboard) {
// 输入请求接口
},
),
),
// 修复使用Expanded包裹ListView确保正确高度
Expanded(
child: ListView.separated(
separatorBuilder: (_, __) => const Divider(height: 0.5, color: Colors.black12,),
itemCount: _dataInfos.length,
itemBuilder: (context, index) {
final item = _dataInfos[index];
return _fxitemCell(item);
},
),
),
],
);
}
Widget _fxitemCell(final item) {
String title = item['title'];
return Container(
height: 50,
color: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 16), // 添加水平内边距
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title),
Icon(Icons.arrow_forward_ios, color: Colors.black26,)
],
),
);
}
void _showMessage(String msg) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
}
}