优化顶部打分bar 和 number 打分栏的rebuild 性能优化

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-09-30 11:11:51 +08:00
parent 2ac88000cc
commit 4161a9fcc8
2 changed files with 157 additions and 160 deletions

View File

@ -6,7 +6,6 @@ import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/marking_models/do_paper_bus.dart';
import 'package:making_school_asignment_app/common/mixins/event_bus_mixin.dart';
import 'package:making_school_asignment_app/common/utils/anti_shake_throttling.dart';
import 'package:making_school_asignment_app/common/utils/utils.dart';
import '../configuration_files/index.dart';
@ -33,7 +32,7 @@ class _BottomAnnotationSwitchJobState extends State<BottomAnnotationSwitch>
lowerBound: 0,
upperBound: 1,
duration: const Duration(milliseconds: 300),
)..addListener(toUp);
);
_opControllisten = _logicControl.opControl.listen((e) {
if (e) {
@ -48,170 +47,174 @@ class _BottomAnnotationSwitchJobState extends State<BottomAnnotationSwitch>
@override
void dispose() {
_animationController
..removeListener(toUp)
..dispose();
_animationController.dispose();
_opControllisten?.cancel();
eventCancel();
super.dispose();
}
void toUp() => toUpState(setState, () {}, mounted);
@override
Widget build(BuildContext context) {
return SafeArea(
left: false,
right: false,
top: false,
child: Container(
width: double.infinity,
height: _animationController.value * 70.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(83, 83, 83, 1),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 8,
offset: const Offset(0, -2),
),
],
),
child: Row(
final Widget barContent = Row(
children: [
Expanded(
flex: 7,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 7,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Row(
children: [
//
Expanded(
child: Row(
children: [
//
Expanded(
child: _buildActionButton(
'全对',
Icons.check_circle_outline,
() => easyThrottle('homework_bottom_operation_bar_scoring_related',
() => _homeworkLogic.allPairs(context)),
isEnabled: !_homeworkLogic.state.submitLoading.value,
isPrimary: true,
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: Obx(() => _buildIconButton(
const IconData(0xe635, fontFamily: "AlibabaIcon"),
() => easyThrottle('homework_bottom_action_bar_annotations', () {
//
_logicControl.gestureMove.value = false;
_logicControl.pen.value = true;
}),
isActive: _logicControl.pen.value,
tooltip: '注解笔',
)),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: Obx(() => _buildIconButton(
const IconData(0xe636, fontFamily: "AlibabaIcon"),
() => easyThrottle('homework_bottom_action_bar_annotations', () {
//
_logicControl.pen.value = false;
_logicControl.gestureMove.value = true;
}),
isActive: _logicControl.gestureMove.value,
tooltip: '滑动试题',
)),
),
],
child: _buildActionButton(
'全对',
Icons.check_circle_outline,
() => easyThrottle(
'homework_bottom_operation_bar_scoring_related', () => _homeworkLogic.allPairs(context)),
isEnabled: !_homeworkLogic.state.submitLoading.value,
isPrimary: true,
),
),
Container(width: double.infinity, color: Colors.white.withOpacity(0.3), height: 0.5.h),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: Row(
children: [
//
Expanded(
child: _buildActionButton(
'全错',
Icons.cancel_outlined,
() => easyThrottle('homework_bottom_operation_bar_scoring_related',
() => _homeworkLogic.allWrongRating(context)),
isEnabled: !_homeworkLogic.state.submitLoading.value,
isPrimary: false,
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: _buildIconButton(
const IconData(0xe638, fontFamily: "AlibabaIcon"),
() => easyThrottle(
'homework_bottom_action_bar_annotations',
() => eventFire(model: BottomOperationBar(revokeAll: false, revokePreStep: true)),
),
tooltip: '撤销上一步',
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: _buildIconButton(
const IconData(0xe637, fontFamily: "AlibabaIcon"),
() => easyThrottle(
'homework_bottom_action_bar_annotations',
() => eventFire(model: BottomOperationBar(revokeAll: true, revokePreStep: false)),
),
tooltip: '全部撤销',
),
),
],
child: Obx(() => _buildIconButton(
const IconData(0xe635, fontFamily: "AlibabaIcon"),
() => easyThrottle('homework_bottom_action_bar_annotations', () {
//
_logicControl.gestureMove.value = false;
_logicControl.pen.value = true;
}),
isActive: _logicControl.pen.value,
tooltip: '注解笔',
)),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: Obx(() => _buildIconButton(
const IconData(0xe636, fontFamily: "AlibabaIcon"),
() => easyThrottle('homework_bottom_action_bar_annotations', () {
//
_logicControl.pen.value = false;
_logicControl.gestureMove.value = true;
}),
isActive: _logicControl.gestureMove.value,
tooltip: '滑动试题',
)),
),
],
),
),
Container(width: double.infinity, color: Colors.white.withOpacity(0.3), height: 0.5.h),
Expanded(
child: Row(
children: [
//
Expanded(
child: _buildActionButton(
'全错',
Icons.cancel_outlined,
() => easyThrottle('homework_bottom_operation_bar_scoring_related',
() => _homeworkLogic.allWrongRating(context)),
isEnabled: !_homeworkLogic.state.submitLoading.value,
isPrimary: false,
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: _buildIconButton(
const IconData(0xe638, fontFamily: "AlibabaIcon"),
() => easyThrottle(
'homework_bottom_action_bar_annotations',
() => eventFire(model: BottomOperationBar(revokeAll: false, revokePreStep: true)),
),
tooltip: '撤销上一步',
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
//
Expanded(
child: _buildIconButton(
const IconData(0xe637, fontFamily: "AlibabaIcon"),
() => easyThrottle(
'homework_bottom_action_bar_annotations',
() => eventFire(model: BottomOperationBar(revokeAll: true, revokePreStep: false)),
),
tooltip: '全部撤销',
),
),
],
),
),
],
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
Expanded(
flex: 3,
child: Row(
children: [
Expanded(
child: _buildActionButton(
'取消',
Icons.clear,
() => easyThrottle(
'homework_bottom_operation_bar_scoring_related', () => _homeworkLogic.cancelAllRatings()),
isEnabled: true,
isPrimary: false,
isSecondary: true,
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
Expanded(
flex: 3,
child: Row(
children: [
Expanded(
child: _buildActionButton(
'取消',
Icons.clear,
() => easyThrottle(
'homework_bottom_operation_bar_scoring_related', () => _homeworkLogic.cancelAllRatings()),
isEnabled: true,
isPrimary: false,
isSecondary: true,
),
),
Container(width: 0.5.w, height: double.infinity, color: Colors.white.withOpacity(0.3)),
Expanded(
child: Obx(() {
final submitLoading = _homeworkLogic.state.submitLoading.value;
return _buildActionButton(
'提交',
Icons.send,
() => easyThrottle(
'homework_bottom_operation_bar_scoring_related', () => _homeworkLogic.submit(context)),
isEnabled: !submitLoading,
isPrimary: true,
isLoading: submitLoading,
);
}),
),
],
),
child: Obx(() {
final submitLoading = _homeworkLogic.state.submitLoading.value;
return _buildActionButton(
'提交',
Icons.send,
() => easyThrottle(
'homework_bottom_operation_bar_scoring_related', () => _homeworkLogic.submit(context)),
isEnabled: !submitLoading,
isPrimary: true,
isLoading: submitLoading,
);
}),
),
],
),
));
),
],
);
return SafeArea(
left: false,
right: false,
top: false,
child: AnimatedBuilder(
animation: _animationController,
builder: (context, _) {
return Container(
width: double.infinity,
height: _animationController.value * 70.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(83, 83, 83, 1),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 8,
offset: const Offset(0, -2),
),
],
),
child: barContent,
);
},
),
);
}
Widget _buildActionButton(

View File

@ -135,28 +135,22 @@ Widget $questionNumberScrollView({
// / I/O
return SingleChildScrollView(
return ListView.builder(
controller: scrollControllerNum,
physics: const BouncingScrollPhysics(),
padding: EdgeInsets.only(top: usePiddingTop.value > 0 ? usePiddingTop.value : 0),
scrollDirection: Axis.vertical, //
child: SizedBox(
height: (actualImgHeight.value ?? 0) * useZoom.value,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: studentQuestions
.map((e) => $ScoringQuestionsView(
key: Key('${sateData.data.value?.templateId}_${sateData.data.value?.studentId}_${e.questionNo}'),
sateData: sateData,
item: e,
logic: controller,
scaleRatio: sateZoomData.zoomFile.value!.scaleRatio,
initScale: useZoom.value,
))
.toList(),
),
),
itemCount: studentQuestions.length,
itemBuilder: (context, index) {
final e = studentQuestions[index];
return $ScoringQuestionsView(
key: Key('${sateData.data.value?.templateId}_${sateData.data.value?.studentId}_${e.questionNo}'),
sateData: sateData,
item: e,
logic: controller,
scaleRatio: sateZoomData.zoomFile.value!.scaleRatio,
initScale: useZoom.value,
);
},
);
}