Files
feature-tenant/lib/features/v2/home/presentation/pages/home_v2_page.dart
2026-05-19 08:46:35 +08:00

191 lines
8.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_bloc.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_event.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_state.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/power_card.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/stats_grid.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/work_order_card.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/quick_entry_card.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/power_trend_chart.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/plant_overview_card.dart';
class HomeV2Page extends StatefulWidget {
const HomeV2Page({super.key});
@override
State<HomeV2Page> createState() => _HomeV2PageState();
}
class _HomeV2PageState extends State<HomeV2Page> {
late HomeV2Bloc _bloc;
@override
void initState() {
super.initState();
_bloc = context.read<HomeV2Bloc>();
_bloc.add(const HomeV2LoadData());
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F7FA),
body: BlocBuilder<HomeV2Bloc, HomeV2State>(
builder: (context, state) {
if (state is HomeV2Loading) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (state is HomeV2Error) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48, color: Color(0xFF86909C)),
const SizedBox(height: 16),
Text(state.message),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _bloc.add(const HomeV2LoadData()),
child: const Text('重试'),
),
],
),
);
}
if (state is HomeV2Loaded) {
return RefreshIndicator(
onRefresh: () async {
_bloc.add(const HomeV2Refresh());
},
child: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
backgroundColor: Colors.white,
elevation: 0,
flexibleSpace: FlexibleSpaceBar(
background: Container(
padding: const EdgeInsets.fromLTRB(16, 40, 16, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Text(
'示例光伏电站',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(width: 4),
const Icon(Icons.arrow_drop_down, size: 20, color: Color(0xFF1D2129)),
const Spacer(),
IconButton(
icon: const Icon(Icons.sentiment_satisfied_alt_outlined, size: 24),
onPressed: () => print('点击表情'),
),
],
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xFFF2F3F5),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.cloud_queue, size: 16, color: Color(0xFF165DFF)),
const SizedBox(width: 6),
const Text(
'多云 28°C',
style: TextStyle(
fontSize: 13,
color: Color(0xFF4E5969),
),
),
],
),
),
),
const SizedBox(width: 8),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xFFFFF0F0),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.warning_amber_rounded, size: 16, color: Color(0xFFF53F3F)),
const SizedBox(width: 6),
const Expanded(
child: Text(
'紧急告警',
style: TextStyle(
fontSize: 13,
color: Color(0xFFF53F3F),
),
),
),
const SizedBox(width: 4),
const Icon(Icons.arrow_forward_ios, size: 12, color: Color(0xFFF53F3F)),
],
),
),
),
],
),
],
),
),
),
),
SliverPadding(
padding: const EdgeInsets.all(16),
sliver: SliverList(
delegate: SliverChildListDelegate([
PowerCard(data: state.homeData),
const SizedBox(height: 12),
StatsGrid(data: state.homeData),
const SizedBox(height: 12),
PlantOverviewCard(overview: state.homeData.plantOverview),
const SizedBox(height: 12),
WorkOrderCard(stats: state.homeData.workOrderStats),
const SizedBox(height: 12),
QuickEntryCard(),
const SizedBox(height: 12),
PowerTrendChart(
data: state.homeData.powerTrendData,
trendType: state.trendType,
onToggleType: (type) => _bloc.add(HomeV2ToggleTrendType(type)),
),
const SizedBox(height: 20),
]),
),
),
],
),
);
}
return const SizedBox();
},
),
);
}
}