优化用户端首页服务归属展示

This commit is contained in:
czl231
2026-09-02 21:59:24 +08:00
parent dd250d80a0
commit 2033a9407e
11 changed files with 321 additions and 37 deletions

View File

@@ -1,9 +1,13 @@
// 功能描述:展示用户端首页的安全内容、服务归属与公告列表。
// 版本1.1.0
import 'package:flutter/material.dart';
import '../../../data/repositories/client_repository.dart';
import '../../../domain/models/client_models.dart';
import '../../core/widgets.dart';
import 'service_relation_card.dart';
/// 用户端首页。
class HomePage extends StatefulWidget {
const HomePage({required this.repository, super.key});
@@ -13,6 +17,7 @@ class HomePage extends StatefulWidget {
State<HomePage> createState() => _HomePageState();
}
/// 管理首页远端数据加载与下拉刷新状态。
class _HomePageState extends State<HomePage> {
late Future<(List<ClientRecord>, Map<String, Object?>?)> _future;
@@ -22,9 +27,11 @@ class _HomePageState extends State<HomePage> {
_future = _load();
}
/// 并行语义上聚合公告和当前服务归属数据。
Future<(List<ClientRecord>, Map<String, Object?>?)> _load() async =>
(await widget.repository.contents(), await widget.repository.serviceRelation());
/// 重新加载首页数据并等待刷新完成。
Future<void> _refresh() async {
setState(() => _future = _load());
await _future;
@@ -59,43 +66,7 @@ class _HomePageState extends State<HomePage> {
description: '设备控制能力尚未开放,本页只展示真实服务与安全内容。',
),
AppGutter(
child: SurfaceSection(
child: Row(
children: [
Container(
width: 52,
height: 52,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(16),
),
child: Icon(
Icons.store_mall_directory_outlined,
color: Theme.of(context).colorScheme.primary,
semanticLabel: '服务归属',
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('当前服务归属', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 4),
Text(
relation == null
? '尚未建立服务关系'
: '${relation['gas_name'] ?? ''} ${relation['delivery_name'] ?? ''}',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
],
),
),
child: ServiceRelationCard(relation: relation),
),
const SizedBox(height: 32),
const AppGutter(

View File

@@ -0,0 +1,112 @@
// 功能描述:展示用户当前所属气站与服务配送点,并处理无配送点和无归属状态。
// 版本1.0.0
import 'package:flutter/material.dart';
import 'package:heqi_design_system/heqi_design_system.dart';
/// 服务归属信息卡片,负责清晰区分气站主体与配送履约网点。
class ServiceRelationCard extends StatelessWidget {
const ServiceRelationCard({required this.relation, super.key});
/// 服务端返回的当前有效服务关系;为空表示尚未建立归属。
final Map<String, Object?>? relation;
/// 提取并清理指定关系字段,空字符串按无值处理。
String? _relationValue(String key) {
final value = relation?[key]?.toString().trim() ?? '';
return value.isEmpty ? null : value;
}
@override
Widget build(BuildContext context) {
final gasName = _relationValue('gas_name');
final deliveryName = _relationValue('delivery_name');
final hasRelation = relation != null && gasName != null;
return HeqiSurfaceSection(
padding: const EdgeInsets.all(HeqiSpacing.x4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(HeqiRadius.extraLarge),
),
child: Icon(
Icons.store_mall_directory_outlined,
size: HeqiSize.iconLarge,
color: Theme.of(context).colorScheme.primary,
semanticLabel: '服务归属',
),
),
const SizedBox(width: HeqiSpacing.x4),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('当前服务归属', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: HeqiSpacing.x3),
if (!hasRelation)
Text(
'尚未建立服务关系',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
)
else ...[
_RelationLine(label: '所属气站', value: gasName),
const Padding(
padding: EdgeInsets.symmetric(vertical: HeqiSpacing.x3),
child: Divider(height: 1),
),
_RelationLine(
label: deliveryName == null ? '服务方式' : '服务配送点',
value: deliveryName ?? '气站直接服务',
),
],
],
),
),
],
),
);
}
}
/// 服务归属中的单行标签和值,名称最多展示两行。
class _RelationLine extends StatelessWidget {
const _RelationLine({required this.label, required this.value});
final String label;
final String value;
@override
Widget build(BuildContext context) => Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 76,
child: Text(
label,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
const SizedBox(width: HeqiSpacing.x2),
Expanded(
child: Text(
value,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
),
],
);
}