158 lines
4.2 KiB
Dart
158 lines
4.2 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:qhd_prevention/customWidget/work_tab_icon_grid.dart';
|
||
|
|
import 'package:qhd_prevention/http/ApiService.dart';
|
||
|
|
import 'package:qhd_prevention/customWidget/IconBadgeButton.dart';
|
||
|
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
||
|
|
import 'package:qhd_prevention/tools/tools.dart';
|
||
|
|
import 'package:qhd_prevention/common/route_aware_state.dart';
|
||
|
|
|
||
|
|
class UnitTabPage extends StatefulWidget {
|
||
|
|
const UnitTabPage({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<UnitTabPage> createState() => _UnitTabPageState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _UnitTabPageState extends RouteAwareState<UnitTabPage> {
|
||
|
|
late List<Map<String, dynamic>> buttonInfos = [
|
||
|
|
{
|
||
|
|
"icon": "assets/images/unit_ico1.png",
|
||
|
|
"title": "服务单位管理",
|
||
|
|
"unreadCount": 0,
|
||
|
|
}
|
||
|
|
,{
|
||
|
|
"icon": "assets/images/unit_ico2.png",
|
||
|
|
"title": "就职单位管理",
|
||
|
|
"unreadCount": 0,
|
||
|
|
}
|
||
|
|
];
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
}
|
||
|
|
Future<void> onVisible() async {
|
||
|
|
_getData();
|
||
|
|
}
|
||
|
|
Future<void> _getData() async {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void _handleIconTap(int index) async {
|
||
|
|
switch (index) {
|
||
|
|
case 0:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
_getData();
|
||
|
|
}
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
double bannerHeight = 618/1125 * MediaQuery.of(context).size.width;
|
||
|
|
const double iconSectionHeight = 150.0;
|
||
|
|
const double iconOverlapBanner = 30.0; // 图标区覆盖 banner 的高度
|
||
|
|
return PopScope(
|
||
|
|
canPop: false,
|
||
|
|
child: Scaffold(
|
||
|
|
extendBodyBehindAppBar: true,
|
||
|
|
appBar: MyAppbar(
|
||
|
|
title: '单位管理',
|
||
|
|
backgroundColor: Colors.transparent,
|
||
|
|
),
|
||
|
|
body: ListView(
|
||
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
||
|
|
padding: EdgeInsets.zero,
|
||
|
|
children: [
|
||
|
|
SizedBox(
|
||
|
|
height: bannerHeight + iconSectionHeight,
|
||
|
|
child: Stack(
|
||
|
|
clipBehavior: Clip.none,
|
||
|
|
children: [
|
||
|
|
Positioned(
|
||
|
|
top: 0,
|
||
|
|
left: 0,
|
||
|
|
right: 0,
|
||
|
|
height: bannerHeight,
|
||
|
|
child: _buildBannerSection(bannerHeight),
|
||
|
|
),
|
||
|
|
Positioned(
|
||
|
|
left: 10,
|
||
|
|
right: 10,
|
||
|
|
top: bannerHeight - iconOverlapBanner,
|
||
|
|
height: iconSectionHeight,
|
||
|
|
child: _buildIconSection(context),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
|
||
|
|
}
|
||
|
|
// 构建顶部 Banner
|
||
|
|
Widget _buildBannerSection(double height) {
|
||
|
|
return Stack(
|
||
|
|
children: [
|
||
|
|
// 背景图片
|
||
|
|
Image.asset(
|
||
|
|
"assets/images/unit_banner.jpg",
|
||
|
|
width: MediaQuery.of(context).size.width,
|
||
|
|
height: height,
|
||
|
|
fit: BoxFit.cover,
|
||
|
|
),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Widget _buildIconSection(BuildContext context) {
|
||
|
|
return Container(
|
||
|
|
padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 5),
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: Colors.white,
|
||
|
|
borderRadius: BorderRadius.circular(12),
|
||
|
|
boxShadow: const [
|
||
|
|
BoxShadow(
|
||
|
|
color: Colors.black12,
|
||
|
|
blurRadius: 6,
|
||
|
|
offset: Offset(0, 2),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
child: Column(
|
||
|
|
children: [
|
||
|
|
_buildIconRow(startIndex: 0),
|
||
|
|
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Widget _buildIconRow({required int startIndex}) {
|
||
|
|
final List<Widget> cells = List.generate(4, (i) {
|
||
|
|
final int idx = startIndex + i;
|
||
|
|
if (idx < buttonInfos.length) {
|
||
|
|
return Expanded(
|
||
|
|
child: Center(child: _buildIconButton(buttonInfos[idx], idx, context)),
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
return const Expanded(
|
||
|
|
child: SizedBox.shrink(),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
return Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||
|
|
children: cells,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Widget _buildIconButton(Map<String, dynamic> info, int index, BuildContext context) {
|
||
|
|
return IconBadgeButton(
|
||
|
|
iconPath: info['icon'] ?? '',
|
||
|
|
title: info['title'] ?? '',
|
||
|
|
unreadCount: (info['unreadCount'] ?? 0) is int ? info['unreadCount'] as int : int.tryParse('${info['unreadCount']}') ?? 0,
|
||
|
|
onTap: () => _handleIconTap(index),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|