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
56619d0f
Commit
56619d0f
authored
Jun 09, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3
parent
7c60f91c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
222 additions
and
96 deletions
+222
-96
inspection_history_cubit.dart
...me/inspection_history/cubit/inspection_history_cubit.dart
+30
-39
inspection_history_state.dart
...me/inspection_history/cubit/inspection_history_state.dart
+4
-19
inspection_history_view.dart
...iews/home/inspection_history/inspection_history_view.dart
+188
-38
No files found.
lib/views/home/inspection_history/cubit/inspection_history_cubit.dart
View file @
56619d0f
...
...
@@ -4,6 +4,8 @@ import 'inspection_history_state.dart';
import
'../../../../services/inspection_history_service.dart'
;
class
InspectionHistoryCubit
extends
Cubit
<
InspectionHistoryState
>
{
static
const
int
pageSize
=
10
;
final
InspectionHistoryService
_service
;
final
int
_deviceIdInt
;
...
...
@@ -12,53 +14,41 @@ class InspectionHistoryCubit extends Cubit<InspectionHistoryState> {
required
InspectionHistoryService
service
,
})
:
_service
=
service
,
_deviceIdInt
=
int
.
tryParse
(
deviceId
)
??
0
,
super
(
InspectionHistoryState
(
deviceId:
deviceId
,
totalCount:
0
,
passCount:
0
,
warningCount:
0
,
failCount:
0
,
records:
[],
))
{
loadHistoryData
();
}
Future
<
void
>
loadHistoryData
()
async
{
emit
(
state
.
copyWith
(
isLoading:
true
,
error:
null
));
try
{
final
result
=
await
_service
.
getList
(
pageSize:
10
,
pageNum:
1
,
deviceId:
_deviceIdInt
,
);
super
(
InspectionHistoryState
(
deviceId:
deviceId
));
final
records
=
result
.
rows
.
map
((
row
)
{
return
InspectionRecord
(
deviceName:
result
.
deviceInfo
.
deviceName
,
inspectorName:
row
.
inspectorName
,
inspectionTime:
row
.
inspectTime
,
result:
row
.
inspectStatus
,
remark:
row
.
remark
,
items:
row
.
itemsDetail
.
map
((
item
)
=>
InspectionItemRecord
(
name:
item
.
name
,
result:
item
.
status
,
))
.
toList
(),
icon:
Icons
.
devices
,
);
}).
toList
();
/// 供 PagingController.fetchPage 回调使用,每次加载新的一页
Future
<
List
<
InspectionRecord
>>
fetchPage
(
int
pageKey
)
async
{
final
result
=
await
_service
.
getList
(
pageSize:
pageSize
,
pageNum:
pageKey
,
deviceId:
_deviceIdInt
,
);
// 首页时更新统计数
if
(
pageKey
==
1
)
{
emit
(
state
.
copyWith
(
isLoading:
false
,
totalCount:
result
.
tabCount
.
total
,
passCount:
result
.
tabCount
.
passCount
,
warningCount:
result
.
tabCount
.
warnCount
,
failCount:
result
.
tabCount
.
failCount
,
records:
records
,
));
}
catch
(
e
)
{
emit
(
state
.
copyWith
(
isLoading:
false
,
error:
e
.
toString
()));
}
return
result
.
rows
.
map
((
row
)
{
return
InspectionRecord
(
deviceName:
result
.
deviceInfo
.
deviceName
,
inspectorName:
row
.
inspectorName
,
inspectionTime:
row
.
inspectTime
,
result:
row
.
inspectStatus
,
remark:
row
.
remark
,
items:
row
.
itemsDetail
.
map
((
item
)
=>
InspectionItemRecord
(
name:
item
.
name
,
result:
item
.
status
,
))
.
toList
(),
icon:
Icons
.
devices
,
);
}).
toList
();
}
}
\ No newline at end of file
lib/views/home/inspection_history/cubit/inspection_history_state.dart
View file @
56619d0f
...
...
@@ -7,19 +7,13 @@ class InspectionHistoryState extends Equatable {
final
int
passCount
;
final
int
warningCount
;
final
int
failCount
;
final
List
<
InspectionRecord
>
records
;
final
bool
isLoading
;
final
String
?
error
;
const
InspectionHistoryState
({
required
this
.
deviceId
,
required
this
.
totalCount
,
required
this
.
passCount
,
required
this
.
warningCount
,
required
this
.
failCount
,
required
this
.
records
,
this
.
isLoading
=
false
,
this
.
error
,
this
.
totalCount
=
0
,
this
.
passCount
=
0
,
this
.
warningCount
=
0
,
this
.
failCount
=
0
,
});
InspectionHistoryState
copyWith
({
...
...
@@ -28,9 +22,6 @@ class InspectionHistoryState extends Equatable {
int
?
passCount
,
int
?
warningCount
,
int
?
failCount
,
List
<
InspectionRecord
>?
records
,
bool
?
isLoading
,
String
?
error
,
})
{
return
InspectionHistoryState
(
deviceId:
deviceId
??
this
.
deviceId
,
...
...
@@ -38,9 +29,6 @@ class InspectionHistoryState extends Equatable {
passCount:
passCount
??
this
.
passCount
,
warningCount:
warningCount
??
this
.
warningCount
,
failCount:
failCount
??
this
.
failCount
,
records:
records
??
this
.
records
,
isLoading:
isLoading
??
this
.
isLoading
,
error:
error
,
);
}
...
...
@@ -51,9 +39,6 @@ class InspectionHistoryState extends Equatable {
passCount
,
warningCount
,
failCount
,
records
,
isLoading
,
error
,
];
}
...
...
lib/views/home/inspection_history/inspection_history_view.dart
View file @
56619d0f
...
...
@@ -2,12 +2,13 @@ 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:infinite_scroll_pagination/infinite_scroll_pagination.dart'
;
import
'package:smart_hotel_app/repositories/inspection_history_repository.dart'
;
import
'package:smart_hotel_app/services/inspection_history_service.dart'
;
import
'cubit/inspection_history_cubit.dart'
;
import
'cubit/inspection_history_state.dart'
;
import
'widget/statistics_card.dart'
;
import
'widget/inspection_record_
list
.dart'
;
import
'widget/inspection_record_
item
.dart'
;
@RoutePage
()
class
InspectionHistoryView
extends
StatelessWidget
{
...
...
@@ -24,51 +25,199 @@ class InspectionHistoryView extends StatelessWidget {
repository:
InspectionHistoryRepository
(),
),
),
child:
Scaffold
(
backgroundColor:
const
Color
.
fromRGBO
(
242
,
243
,
245
,
1
),
appBar:
AppBar
(
backgroundColor:
Colors
.
white
,
elevation:
0
,
leading:
IconButton
(
icon:
const
Icon
(
Icons
.
arrow_back_ios
,
color:
Color
.
fromRGBO
(
100
,
116
,
139
,
1
)),
onPressed:
()
{
context
.
popRoute
();
},
),
title:
Text
(
'巡检记录'
,
style:
TextStyle
(
color:
const
Color
.
fromRGBO
(
10
,
13
,
20
,
1
),
fontSize:
32
.
sp
,
fontWeight:
FontWeight
.
w200
,
child:
const
_InspectionHistoryBody
(),
);
}
}
class
_InspectionHistoryBody
extends
StatefulWidget
{
const
_InspectionHistoryBody
();
@override
State
<
_InspectionHistoryBody
>
createState
()
=>
_InspectionHistoryBodyState
();
}
class
_InspectionHistoryBodyState
extends
State
<
_InspectionHistoryBody
>
{
late
final
PagingController
<
int
,
InspectionRecord
>
_pagingController
;
@override
void
initState
()
{
super
.
initState
();
_pagingController
=
PagingController
<
int
,
InspectionRecord
>(
getNextPageKey:
(
state
)
{
if
(
state
.
keys
==
null
||
state
.
keys
!.
isEmpty
)
return
1
;
final
total
=
context
.
read
<
InspectionHistoryCubit
>().
state
.
totalCount
;
final
nextKey
=
state
.
nextIntPageKey
;
if
(
nextKey
==
null
)
return
null
;
if
((
nextKey
-
1
)
*
InspectionHistoryCubit
.
pageSize
>=
total
)
{
return
null
;
}
return
nextKey
;
},
fetchPage:
(
pageKey
)
=>
context
.
read
<
InspectionHistoryCubit
>().
fetchPage
(
pageKey
),
);
}
@override
void
dispose
()
{
_pagingController
.
dispose
();
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
BlocBuilder
<
InspectionHistoryCubit
,
InspectionHistoryState
>(
builder:
(
context
,
state
)
{
return
Scaffold
(
backgroundColor:
const
Color
.
fromRGBO
(
242
,
243
,
245
,
1
),
appBar:
AppBar
(
backgroundColor:
Colors
.
white
,
elevation:
0
,
leading:
IconButton
(
icon:
const
Icon
(
Icons
.
arrow_back_ios
,
color:
Color
.
fromRGBO
(
100
,
116
,
139
,
1
)),
onPressed:
()
{
context
.
popRoute
();
},
),
title:
Text
(
'巡检记录'
,
style:
TextStyle
(
color:
const
Color
.
fromRGBO
(
10
,
13
,
20
,
1
),
fontSize:
32
.
sp
,
fontWeight:
FontWeight
.
w200
,
),
),
centerTitle:
true
,
),
centerTitle:
true
,
),
body:
SingleChildScrollView
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
28
.
w
,
vertical:
20
.
h
),
child:
BlocBuilder
<
InspectionHistoryCubit
,
InspectionHistoryState
>(
builder:
(
context
,
state
)
{
return
Column
(
children:
[
StatisticsCard
(
totalCount:
state
.
totalCount
,
passCount:
state
.
passCount
,
warningCount:
state
.
warningCount
,
failCount:
state
.
failCount
,
body:
PagingListener
<
int
,
InspectionRecord
>(
controller:
_pagingController
,
builder:
(
context
,
pagingState
,
fetchNextPage
)
{
return
CustomScrollView
(
slivers:
[
SliverToBoxAdapter
(
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
28
.
w
,
vertical:
20
.
h
),
child:
StatisticsCard
(
totalCount:
state
.
totalCount
,
passCount:
state
.
passCount
,
warningCount:
state
.
warningCount
,
failCount:
state
.
failCount
,
),
),
),
SliverToBoxAdapter
(
child:
Padding
(
padding:
EdgeInsets
.
only
(
left:
28
.
w
,
right:
28
.
w
,
bottom:
16
.
h
),
child:
Row
(
children:
[
Text
(
'巡检历史'
,
style:
TextStyle
(
fontSize:
28
.
sp
,
fontWeight:
FontWeight
.
bold
,
color:
const
Color
.
fromRGBO
(
10
,
13
,
20
,
1.0
),
),
),
Text
(
' (
${state.totalCount}
)'
,
style:
TextStyle
(
fontSize:
28
.
sp
,
fontWeight:
FontWeight
.
bold
,
color:
const
Color
.
fromRGBO
(
10
,
13
,
20
,
1.0
),
),
),
],
),
),
),
SizedBox
(
height:
20
.
h
),
InspectionRecordList
(
records:
state
.
records
,
SliverPadding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
28
.
w
),
sliver:
PagedSliverList
<
int
,
InspectionRecord
>(
state:
pagingState
,
fetchNextPage:
fetchNextPage
,
builderDelegate:
PagedChildBuilderDelegate
<
InspectionRecord
>(
firstPageErrorIndicatorBuilder:
(
_
)
=>
Center
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Text
(
'加载失败:
${pagingState.error}
'
,
style:
TextStyle
(
fontSize:
28
.
sp
,
color:
const
Color
.
fromRGBO
(
255
,
100
,
101
,
1
),
),
textAlign:
TextAlign
.
center
,
),
SizedBox
(
height:
24
.
h
),
ElevatedButton
(
onPressed:
fetchNextPage
,
child:
Text
(
'重新加载'
,
style:
TextStyle
(
fontSize:
28
.
sp
)),
),
],
),
),
noItemsFoundIndicatorBuilder:
(
_
)
=>
Padding
(
padding:
EdgeInsets
.
only
(
top:
60
.
h
),
child:
Text
(
'暂无数据'
,
style:
TextStyle
(
fontSize:
28
.
sp
,
color:
const
Color
.
fromRGBO
(
100
,
116
,
139
,
1
),
),
),
),
newPageErrorIndicatorBuilder:
(
_
)
=>
Center
(
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
20
.
h
),
child:
Column
(
children:
[
Text
(
'加载失败:
${pagingState.error}
'
,
style:
TextStyle
(
fontSize:
24
.
sp
,
color:
const
Color
.
fromRGBO
(
255
,
100
,
101
,
1
),
),
),
SizedBox
(
height:
12
.
h
),
TextButton
(
onPressed:
fetchNextPage
,
child:
Text
(
'重试'
,
style:
TextStyle
(
fontSize:
24
.
sp
)),
),
],
),
),
),
itemBuilder:
(
_
,
item
,
__
)
{
return
InspectionRecordItem
(
record:
item
);
},
),
),
),
SliverToBoxAdapter
(
child:
SizedBox
(
height:
30
.
h
),
),
SizedBox
(
height:
30
.
h
),
],
);
},
),
)
,
)
,
)
;
}
,
);
}
}
\ No newline at end of file
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