Skip to content

Commit

Permalink
mod: 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Mar 1, 2024
1 parent ba64a80 commit 12ebe0a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/pages/danmaku/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class _PlDanmakuState extends State<PlDanmaku> {
// 播放器状态监听
void playerListener(PlayerStatus? status) {
if (status == PlayerStatus.paused) {
_controller!.pause();
_controller?.pause();
}
if (status == PlayerStatus.playing) {
_controller!.onResume();
_controller?.onResume();
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ class PlPlayerController {

/// 触发回调事件
for (var element in _statusListeners) {
element(event ? PlayerStatus.playing : PlayerStatus.paused);
if (element != null) {
element(event ? PlayerStatus.playing : PlayerStatus.paused);
}
}
if (videoPlayerController!.state.position.inSeconds != 0) {
makeHeartBeat(positionSeconds.value, type: 'status');
Expand Down
60 changes: 30 additions & 30 deletions lib/plugin/pl_player/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -655,36 +655,36 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
timeLabelLocation: TimeLabelLocation.none,
thumbColor: colorTheme,
barHeight: 3.5,
thumbRadius: draggingFixedProgressBar.value ? 7 : 4,
onDragStart: (duration) {
draggingFixedProgressBar.value = true;
feedBack();
_.onChangedSliderStart();
},
onDragUpdate: (duration) {
double newProgress = duration.timeStamp.inSeconds / max;
if ((newProgress - _lastAnnouncedValue).abs() > 0.02) {
_accessibilityDebounce?.cancel();
_accessibilityDebounce =
Timer(const Duration(milliseconds: 200), () {
SemanticsService.announce(
"${(newProgress * 100).round()}%",
TextDirection.ltr);
_lastAnnouncedValue = newProgress;
});
}
_.onUpdatedSliderProgress(duration.timeStamp);
},
onSeek: (duration) {
draggingFixedProgressBar.value = false;
_.onChangedSliderEnd();
_.onChangedSlider(duration.inSeconds.toDouble());
_.seekTo(Duration(seconds: duration.inSeconds),
type: 'slider');
SemanticsService.announce(
"${(duration.inSeconds / max * 100).round()}%",
TextDirection.ltr);
},
thumbRadius: draggingFixedProgressBar.value ? 7 : 2.5,
// onDragStart: (duration) {
// draggingFixedProgressBar.value = true;
// feedBack();
// _.onChangedSliderStart();
// },
// onDragUpdate: (duration) {
// double newProgress = duration.timeStamp.inSeconds / max;
// if ((newProgress - _lastAnnouncedValue).abs() > 0.02) {
// _accessibilityDebounce?.cancel();
// _accessibilityDebounce =
// Timer(const Duration(milliseconds: 200), () {
// SemanticsService.announce(
// "${(newProgress * 100).round()}%",
// TextDirection.ltr);
// _lastAnnouncedValue = newProgress;
// });
// }
// _.onUpdatedSliderProgress(duration.timeStamp);
// },
// onSeek: (duration) {
// draggingFixedProgressBar.value = false;
// _.onChangedSliderEnd();
// _.onChangedSlider(duration.inSeconds.toDouble());
// _.seekTo(Duration(seconds: duration.inSeconds),
// type: 'slider');
// SemanticsService.announce(
// "${(duration.inSeconds / max * 100).round()}%",
// TextDirection.ltr);
// },
),
// SlideTransition(
// position: Tween<Offset>(
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Grid {
static double calculateActualWidth(BuildContext context, double maxCrossAxisExtent, double crossAxisSpacing) {
double screenWidth = MediaQuery.of(context).size.width;
int columnCount = ((screenWidth - crossAxisSpacing) / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
if (columnCount < 1){
columnCount = 1;
}
double columnWidth = (screenWidth - crossAxisSpacing) ~/ columnCount - crossAxisSpacing;
return columnWidth;
}
Expand Down

0 comments on commit 12ebe0a

Please sign in to comment.