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

View File

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