refactor: progressBar
This commit is contained in:
@ -842,8 +842,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
total: Duration(seconds: max),
|
total: Duration(seconds: max),
|
||||||
progressBarColor: colorTheme,
|
progressBarColor: colorTheme,
|
||||||
baseBarColor: Colors.white.withOpacity(0.2),
|
baseBarColor: Colors.white.withOpacity(0.2),
|
||||||
bufferedBarColor:
|
bufferedBarColor: Colors.white.withOpacity(0.6),
|
||||||
Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
|
||||||
timeLabelLocation: TimeLabelLocation.none,
|
timeLabelLocation: TimeLabelLocation.none,
|
||||||
thumbColor: colorTheme,
|
thumbColor: colorTheme,
|
||||||
barHeight: 3,
|
barHeight: 3,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'progress_bar.dart';
|
||||||
|
|
||||||
class BottomControl extends StatelessWidget implements PreferredSizeWidget {
|
class BottomControl extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final PlPlayerController? controller;
|
final PlPlayerController? controller;
|
||||||
@ -20,54 +18,18 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Color colorTheme = Theme.of(context).colorScheme.primary;
|
|
||||||
final _ = controller!;
|
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
height: 90,
|
height: 90,
|
||||||
padding: const EdgeInsets.only(left: 18, right: 18),
|
padding: const EdgeInsets.symmetric(horizontal: 18),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Obx(
|
Padding(
|
||||||
() {
|
padding: const EdgeInsets.fromLTRB(7, 0, 7, 6),
|
||||||
final int value = _.sliderPositionSeconds.value;
|
child: ProgressBarWidget(controller: controller!),
|
||||||
final int max = _.durationSeconds.value;
|
|
||||||
final int buffer = _.bufferedSeconds.value;
|
|
||||||
if (value > max || max <= 0) {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 7, right: 7, bottom: 6),
|
|
||||||
child: ProgressBar(
|
|
||||||
progress: Duration(seconds: value),
|
|
||||||
buffered: Duration(seconds: buffer),
|
|
||||||
total: Duration(seconds: max),
|
|
||||||
progressBarColor: colorTheme,
|
|
||||||
baseBarColor: Colors.white.withOpacity(0.2),
|
|
||||||
bufferedBarColor: colorTheme.withOpacity(0.4),
|
|
||||||
timeLabelLocation: TimeLabelLocation.none,
|
|
||||||
thumbColor: colorTheme,
|
|
||||||
barHeight: 3.5,
|
|
||||||
thumbRadius: 7,
|
|
||||||
onDragStart: (duration) {
|
|
||||||
feedBack();
|
|
||||||
_.onChangedSliderStart();
|
|
||||||
},
|
|
||||||
onDragUpdate: (duration) {
|
|
||||||
_.onUpdatedSliderProgress(duration.timeStamp);
|
|
||||||
},
|
|
||||||
onSeek: (duration) {
|
|
||||||
_.onChangedSliderEnd();
|
|
||||||
_.onChangedSlider(duration.inSeconds.toDouble());
|
|
||||||
_.seekTo(Duration(seconds: duration.inSeconds),
|
|
||||||
type: 'slider');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
Row(children: [...buildBottomControl!]),
|
Row(children: buildBottomControl!),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
52
lib/plugin/pl_player/widgets/progress_bar.dart
Normal file
52
lib/plugin/pl_player/widgets/progress_bar.dart
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
|
|
||||||
|
class ProgressBarWidget extends StatelessWidget {
|
||||||
|
final PlPlayerController controller;
|
||||||
|
|
||||||
|
const ProgressBarWidget({
|
||||||
|
required this.controller,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Obx(() {
|
||||||
|
Color colorTheme = Theme.of(context).colorScheme.primary;
|
||||||
|
final _ = controller;
|
||||||
|
final int value = _.sliderPositionSeconds.value;
|
||||||
|
final int max = _.durationSeconds.value;
|
||||||
|
final int buffer = _.bufferedSeconds.value;
|
||||||
|
if (value > max || max <= 0) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
return ProgressBar(
|
||||||
|
progress: Duration(seconds: value),
|
||||||
|
buffered: Duration(seconds: buffer),
|
||||||
|
total: Duration(seconds: max),
|
||||||
|
progressBarColor: colorTheme,
|
||||||
|
baseBarColor: Colors.white.withOpacity(0.2),
|
||||||
|
bufferedBarColor: Colors.white.withOpacity(0.6),
|
||||||
|
timeLabelLocation: TimeLabelLocation.none,
|
||||||
|
thumbColor: colorTheme,
|
||||||
|
barHeight: 3.5,
|
||||||
|
thumbRadius: 7,
|
||||||
|
onDragStart: (duration) {
|
||||||
|
feedBack();
|
||||||
|
_.onChangedSliderStart();
|
||||||
|
},
|
||||||
|
onDragUpdate: (duration) {
|
||||||
|
_.onUpdatedSliderProgress(duration.timeStamp);
|
||||||
|
},
|
||||||
|
onSeek: (duration) {
|
||||||
|
_.onChangedSliderEnd();
|
||||||
|
_.onChangedSlider(duration.inSeconds.toDouble());
|
||||||
|
_.seekTo(Duration(seconds: duration.inSeconds), type: 'slider');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user