Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smart_hotel_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宏
smart_hotel_app
Commits
75c1ef0e
Commit
75c1ef0e
authored
Jun 11, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tab调整
parent
168178cd
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
163 additions
and
30 deletions
+163
-30
home_index_cubit.dart
lib/views/home/index/cubit/home_index_cubit.dart
+5
-2
index_view.dart
lib/views/home/index/index_view.dart
+34
-9
temperature_block.dart
lib/views/home/index/widget/temperature_block.dart
+2
-2
default_view.dart
lib/views/layout/default_view.dart
+12
-1
energy_cubit.dart
lib/views/report/energy/cubit/energy_cubit.dart
+4
-0
report_index_cubit.dart
lib/views/report/index/cubit/report_index_cubit.dart
+4
-0
index_view.dart
lib/views/report/index/index_view.dart
+31
-5
service_index_cubit.dart
lib/views/service/index/cubit/service_index_cubit.dart
+8
-2
index_view.dart
lib/views/service/index/index_view.dart
+32
-7
技术方案.md
技术方案.md
+31
-2
No files found.
lib/views/home/index/cubit/home_index_cubit.dart
View file @
75c1ef0e
...
...
@@ -27,6 +27,10 @@ class HomeIndexCubit extends Cubit<HomeIndexState> {
}
}
Future
<
void
>
reloadDashboard
()
async
{
loadDashboard
();
}
void
_emitFromDashboard
(
AlertDashboardBO
dashboard
)
{
emit
(
state
.
copyWith
(
isLoading:
false
,
...
...
@@ -91,4 +95,4 @@ class HomeIndexCubit extends Cubit<HomeIndexState> {
return
const
Color
.
fromRGBO
(
26
,
188
,
156
,
1.0
);
}
}
}
\ No newline at end of file
}
lib/views/home/index/index_view.dart
View file @
75c1ef0e
...
...
@@ -12,16 +12,43 @@ import 'package:smart_hotel_app/views/home/index/widget/temperature_block.dart';
import
'package:smart_hotel_app/views/home/index/widget/voltage_operate_block.dart'
;
@RoutePage
()
class
HomeView
extends
State
less
Widget
{
class
HomeView
extends
State
ful
Widget
{
const
HomeView
({
super
.
key
});
@override
State
<
HomeView
>
createState
()
=>
_HomeViewState
();
}
class
_HomeViewState
extends
State
<
HomeView
>
with
AutoRouteAwareStateMixin
<
HomeView
>
{
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
// Subscribe to tab router events
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
addListener
(
_onTabChange
);
}
@override
void
dispose
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
removeListener
(
_onTabChange
);
super
.
dispose
();
}
void
_onTabChange
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
// Check if this tab is now active
if
(
tabsRouter
.
activeIndex
==
0
)
{
// Reload data when tab is activated
context
.
read
<
HomeIndexCubit
>().
reloadDashboard
();
}
}
@override
Widget
build
(
BuildContext
context
)
{
return
BlocProvider
(
create:
(
_
)
=>
HomeIndexCubit
(),
child:
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
SingleChildScrollView
(
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
SingleChildScrollView
(
child:
ConstrainedBox
(
constraints:
BoxConstraints
(
minHeight:
constraints
.
maxHeight
,
...
...
@@ -55,7 +82,6 @@ class HomeView extends StatelessWidget {
),
);
},
),
);
}
...
...
@@ -96,4 +122,4 @@ class HomeView extends StatelessWidget {
}
return
blocks
;
}
}
\ No newline at end of file
}
lib/views/home/index/widget/temperature_block.dart
View file @
75c1ef0e
...
...
@@ -125,7 +125,7 @@ class TemperatureBlock extends StatelessWidget {
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Text
(
'
${currentVoltage}
V
'
,
'
${currentVoltage}
'
,
style:
TextStyle
(
fontSize:
40
.
sp
,
fontWeight:
FontWeight
.
bold
,
...
...
@@ -148,7 +148,7 @@ class TemperatureBlock extends StatelessWidget {
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Text
(
'
${currentCurrent}
A
'
,
'
${currentCurrent}
'
,
style:
TextStyle
(
fontSize:
40
.
sp
,
fontWeight:
FontWeight
.
bold
,
...
...
lib/views/layout/default_view.dart
View file @
75c1ef0e
import
'package:auto_route/auto_route.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
import
'package:smart_hotel_app/routes/app_router.gr.dart'
;
import
'package:smart_hotel_app/views/home/index/cubit/home_index_cubit.dart'
;
import
'package:smart_hotel_app/views/report/index/cubit/report_index_cubit.dart'
;
import
'package:smart_hotel_app/views/service/index/cubit/service_index_cubit.dart'
;
@RoutePage
()
class
DefaultLayoutView
extends
StatefulWidget
{
...
...
@@ -14,7 +18,13 @@ class DefaultLayoutView extends StatefulWidget {
class
_DefaultLayoutViewState
extends
State
<
DefaultLayoutView
>
{
@override
Widget
build
(
BuildContext
context
)
{
return
AutoTabsScaffold
(
return
MultiBlocProvider
(
providers:
[
BlocProvider
(
create:
(
_
)
=>
HomeIndexCubit
()),
BlocProvider
(
create:
(
_
)
=>
ServiceIndexCubit
()),
BlocProvider
(
create:
(
_
)
=>
ReportIndexCubit
()),
],
child:
AutoTabsScaffold
(
routes:
const
[
HomeRoute
(),
ServiceIndexRoute
(),
ReportIndexRoute
(),
ProfileRoute
()],
transitionBuilder:
(
context
,
child
,
animation
)
=>
child
,
bottomNavigationBuilder:
(
context
,
tabsRouter
)
{
...
...
@@ -92,6 +102,7 @@ class _DefaultLayoutViewState extends State<DefaultLayoutView> {
),
);
},
),
);
}
}
lib/views/report/energy/cubit/energy_cubit.dart
View file @
75c1ef0e
...
...
@@ -23,6 +23,10 @@ class EnergyCubit extends Cubit<EnergyState> {
}
}
Future
<
void
>
reloadData
()
async
{
loadData
();
}
EnergyState
_mapAnalysisToState
(
EnergyAnalysisBO
data
)
{
// 计算今日变化百分比
double
todayChange
=
0
;
...
...
lib/views/report/index/cubit/report_index_cubit.dart
View file @
75c1ef0e
...
...
@@ -24,6 +24,10 @@ class ReportIndexCubit extends Cubit<ReportIndexState> {
}
}
Future
<
void
>
reloadData
()
async
{
loadData
();
}
ReportIndexState
_mapOverviewToState
(
DashboardOverviewBO
overview
)
{
// 今日用电指标
final
elec
=
overview
.
electricityToday
;
...
...
lib/views/report/index/index_view.dart
View file @
75c1ef0e
...
...
@@ -12,14 +12,41 @@ import 'package:smart_hotel_app/views/report/index/widget/room_status_distributi
import
'package:smart_hotel_app/views/report/index/widget/weekly_power_chart.dart'
;
@RoutePage
()
class
ReportIndexView
extends
State
less
Widget
{
class
ReportIndexView
extends
State
ful
Widget
{
const
ReportIndexView
({
super
.
key
});
@override
State
<
ReportIndexView
>
createState
()
=>
_ReportIndexViewState
();
}
class
_ReportIndexViewState
extends
State
<
ReportIndexView
>
with
AutoRouteAwareStateMixin
<
ReportIndexView
>
{
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
// Subscribe to tab router events
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
addListener
(
_onTabChange
);
}
@override
void
dispose
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
removeListener
(
_onTabChange
);
super
.
dispose
();
}
void
_onTabChange
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
// Check if this tab is now active (index 2)
if
(
tabsRouter
.
activeIndex
==
2
)
{
// Reload data when tab is activated
context
.
read
<
ReportIndexCubit
>().
reloadData
();
}
}
@override
Widget
build
(
BuildContext
context
)
{
return
BlocProvider
(
create:
(
_
)
=>
ReportIndexCubit
(),
child:
BlocBuilder
<
ReportIndexCubit
,
ReportIndexState
>(
return
BlocBuilder
<
ReportIndexCubit
,
ReportIndexState
>(
builder:
(
context
,
state
)
{
if
(
state
.
isLoading
)
{
return
Container
(
...
...
@@ -95,7 +122,6 @@ class ReportIndexView extends StatelessWidget {
},
);
},
),
);
}
}
lib/views/service/index/cubit/service_index_cubit.dart
View file @
75c1ef0e
...
...
@@ -28,6 +28,13 @@ class ServiceIndexCubit extends Cubit<ServiceIndexState> {
]);
}
Future
<
void
>
reloadAll
()
async
{
await
Future
.
wait
([
loadStatistics
(),
loadFloorAndAreas
(),
]);
}
/// 加载客房服务看板-统计数据(待响应、入住中、空闲可清洁)
Future
<
void
>
loadStatistics
()
async
{
emit
(
state
.
copyWith
(
isLoading:
true
,
error:
null
));
...
...
@@ -231,4 +238,4 @@ class ServiceIndexCubit extends Cubit<ServiceIndexState> {
}
return
null
;
}
}
\ No newline at end of file
}
lib/views/service/index/index_view.dart
View file @
75c1ef0e
...
...
@@ -9,14 +9,41 @@ import 'package:smart_hotel_app/views/service/index/widget/service_head_block.da
import
'package:smart_hotel_app/views/service/index/widget/service_stats_block.dart'
;
@RoutePage
()
class
ServiceIndexView
extends
State
less
Widget
{
class
ServiceIndexView
extends
State
ful
Widget
{
const
ServiceIndexView
({
super
.
key
});
@override
State
<
ServiceIndexView
>
createState
()
=>
_ServiceIndexViewState
();
}
class
_ServiceIndexViewState
extends
State
<
ServiceIndexView
>
with
AutoRouteAwareStateMixin
<
ServiceIndexView
>
{
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
// Subscribe to tab router events
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
addListener
(
_onTabChange
);
}
@override
void
dispose
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
tabsRouter
.
removeListener
(
_onTabChange
);
super
.
dispose
();
}
void
_onTabChange
()
{
final
tabsRouter
=
AutoTabsRouter
.
of
(
context
);
// Check if this tab is now active (index 1)
if
(
tabsRouter
.
activeIndex
==
1
)
{
// Reload data when tab is activated
context
.
read
<
ServiceIndexCubit
>().
reloadAll
();
}
}
@override
Widget
build
(
BuildContext
context
)
{
return
BlocProvider
(
create:
(
_
)
=>
ServiceIndexCubit
(),
child:
LayoutBuilder
(
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
SingleChildScrollView
(
child:
ConstrainedBox
(
...
...
@@ -46,7 +73,6 @@ class ServiceIndexView extends StatelessWidget {
),
);
},
),
);
}
}
\ No newline at end of file
}
技术方案.md
View file @
75c1ef0e
# 智慧酒
店 App 技术方案
# 智慧酒
店 App 技术方案
...
...
@@ -47,7 +47,36 @@
└─────────────────────────────────────────────┘
```
### 2.2 依赖注入
### 2.3 Provider 分层结构
项目通过
`MultiBlocProvider`
的嵌套实现不同作用域的状态管理:
```
MaterialApp (main.dart)
└─ MultiBlocProvider (全局)
├─ AuthBloc ← 所有页面都能访问
│
├─ LoginRoute() ← 可以 read<AuthBloc>
│
└─ DefaultLayoutRoute() ← 可以 read<AuthBloc>
└─ MultiBlocProvider (仅主页范围)
├─ HomeIndexCubit ← 仅在 tab 页面内可访问
├─ ServiceIndexCubit ← 仅在 tab 页面内可访问
├─ ReportIndexCubit ← 仅在 tab 页面内可访问
│
└─ AutoTabsScaffold
├─ HomeView ← 可以 read<AuthBloc> + read<HomeIndexCubit>
├─ ServiceView ← 可以 read<AuthBloc> + read<ServiceIndexCubit>
├─ ReportView ← 可以 read<AuthBloc> + read<ReportIndexCubit>
└─ ProfileView ← 可以 read<AuthBloc>(但不能读上面三个Cubit)
```
| 层级 | 定义位置 | 作用域 | 提供者 | 特点 |
|------|---------|--------|--------|------|
| 全局 Provider |
`main.dart`
| 整个 App |
`AuthBloc`
(认证) |
`.value()`
复用已有实例,App 存活期间一直存在 |
| 主页 Provider |
`default_view.dart`
| 仅底部 Tab 页面 |
`HomeIndexCubit`
、
`ServiceIndexCubit`
、
`ReportIndexCubit`
|
`create`
创建新实例,仅在主页存活期间存在 |
**子 `MultiBlocProvider` 可以访问父 `MultiBlocProvider` 提供的内容**
(tab 页面中
`context.read<AuthBloc>()`
依然有效),反过来不行(
`AuthBloc`
里不能读取业务 Cubit)。
项目未使用 DI 框架(如 get_it),而是采用
**手动注入**
方式。在
`main.dart`
的
`_MyAppState.initState()`
中集中创建核心单例,通过构造函数向下传递。
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment