Skip to content

Commit 1d60005

Browse files
alguintuKaival-Patel
authored andcommitted
add smooth_video_progress.dart from smooth_video_progress package, dependencies version bump
1 parent 6b03c2b commit 1d60005

File tree

4 files changed

+110
-27
lines changed

4 files changed

+110
-27
lines changed

example/pubspec.lock

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ packages:
2121
dependency: "direct main"
2222
description:
2323
name: cached_network_image
24-
sha256: "28ea9690a8207179c319965c13cd8df184d5ee721ae2ce60f398ced1219cea1f"
24+
sha256: "4a5d8d2c728b0f3d0245f69f921d7be90cae4c2fd5288f773088672c0893f819"
2525
url: "https://pub.dev"
2626
source: hosted
27-
version: "3.3.1"
27+
version: "3.4.0"
2828
cached_network_image_platform_interface:
2929
dependency: transitive
3030
description:
3131
name: cached_network_image_platform_interface
32-
sha256: "9e90e78ae72caa874a323d78fa6301b3fb8fa7ea76a8f96dc5b5bf79f283bf2f"
32+
sha256: ff0c949e323d2a1b52be73acce5b4a7b04063e61414c8ca542dbba47281630a7
3333
url: "https://pub.dev"
3434
source: hosted
35-
version: "4.0.0"
35+
version: "4.1.0"
3636
cached_network_image_web:
3737
dependency: transitive
3838
description:
3939
name: cached_network_image_web
40-
sha256: "205d6a9f1862de34b93184f22b9d2d94586b2f05c581d546695e3d8f6a805cd7"
40+
sha256: "6322dde7a5ad92202e64df659241104a43db20ed594c41ca18de1014598d7996"
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.2.0"
43+
version: "1.3.0"
4444
characters:
4545
dependency: transitive
4646
description:
@@ -138,18 +138,18 @@ packages:
138138
dependency: transitive
139139
description:
140140
name: flutter_cache_manager
141-
sha256: "395d6b7831f21f3b989ebedbb785545932adb9afe2622c1ffacf7f4b53a7e544"
141+
sha256: a77f77806a790eb9ba0118a5a3a936e81c4fea2b61533033b2b0c3d50bbde5ea
142142
url: "https://pub.dev"
143143
source: hosted
144-
version: "3.3.2"
144+
version: "3.4.0"
145145
flutter_hooks:
146146
dependency: transitive
147147
description:
148148
name: flutter_hooks
149-
sha256: "6a126f703b89499818d73305e4ce1e3de33b4ae1c5512e3b8eab4b986f46774c"
149+
sha256: cde36b12f7188c85286fba9b38cc5a902e7279f36dd676967106c041dc9dde70
150150
url: "https://pub.dev"
151151
source: hosted
152-
version: "0.18.6"
152+
version: "0.20.5"
153153
flutter_inappwebview:
154154
dependency: transitive
155155
description:
@@ -323,10 +323,10 @@ packages:
323323
dependency: transitive
324324
description:
325325
name: octo_image
326-
sha256: "45b40f99622f11901238e18d48f5f12ea36426d8eced9f4cbf58479c7aa2430d"
326+
sha256: "34faa6639a78c7e3cbe79be6f9f96535867e879748ade7d17c9b1ae7536293bd"
327327
url: "https://pub.dev"
328328
source: hosted
329-
version: "2.0.0"
329+
version: "2.1.0"
330330
path:
331331
dependency: "direct main"
332332
description:
@@ -420,14 +420,6 @@ packages:
420420
description: flutter
421421
source: sdk
422422
version: "0.0.99"
423-
smooth_video_progress:
424-
dependency: transitive
425-
description:
426-
name: smooth_video_progress
427-
sha256: a47efa055d4f0d7634ffa7c43197d71a30c98f31fffe4bbe1a949c4b851c68db
428-
url: "https://pub.dev"
429-
source: hosted
430-
version: "0.0.4"
431423
source_span:
432424
dependency: transitive
433425
description:
@@ -536,10 +528,10 @@ packages:
536528
dependency: transitive
537529
description:
538530
name: video_player
539-
sha256: aced48e701e24c02b0b7f881a8819e4937794e46b5a5821005e2bf3b40a324cc
531+
sha256: e30df0d226c4ef82e2c150ebf6834b3522cf3f654d8e2f9419d376cdc071425d
540532
url: "https://pub.dev"
541533
source: hosted
542-
version: "2.8.7"
534+
version: "2.9.1"
543535
video_player_android:
544536
dependency: transitive
545537
description:

lib/src/story_presenter/story_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import '../story_presenter/image_story_view.dart';
88
import '../story_presenter/video_story_view.dart';
99
import '../story_presenter/web_story_view.dart';
1010
import '../story_presenter/text_story_view.dart';
11+
import '../utils/smooth_video_progress.dart';
1112
import '../utils/story_utils.dart';
12-
import 'package:smooth_video_progress/smooth_video_progress.dart';
1313
import 'package:video_player/video_player.dart';
1414

1515
typedef OnStoryChanged = void Function(int);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
library smooth_video_progress;
2+
3+
import 'package:flutter/widgets.dart';
4+
import 'package:flutter_hooks/flutter_hooks.dart';
5+
import 'package:video_player/video_player.dart';
6+
7+
/// A widget that provides a method of building widgets using an interpolated
8+
/// position value for [VideoPlayerController].
9+
class SmoothVideoProgress extends HookWidget {
10+
const SmoothVideoProgress({
11+
super.key,
12+
required this.controller,
13+
required this.builder,
14+
this.child,
15+
});
16+
17+
/// The [VideoPlayerController] to build a progress widget for.
18+
final VideoPlayerController controller;
19+
20+
/// The builder function.
21+
///
22+
/// [progress] holds the interpolated current progress of the video. Use
23+
/// [duration] (the total duration of the video) to calculate a relative value
24+
/// for a slider for example for convenience.
25+
/// [child] holds the widget you passed into the constructor of this widget.
26+
/// Use that to optimize rebuilds.
27+
final Widget Function(BuildContext context, Duration progress,
28+
Duration duration, Widget? child) builder;
29+
30+
/// An optional child that will be passed to the [builder] function and helps
31+
/// you optimize rebuilds.
32+
final Widget? child;
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
final value = useValueListenable(controller);
37+
final animationController = useAnimationController(
38+
duration: value.duration, keys: [value.duration]);
39+
40+
final targetRelativePosition =
41+
value.position.inMilliseconds / value.duration.inMilliseconds;
42+
43+
final currentPosition = Duration(
44+
milliseconds:
45+
(animationController.value * value.duration.inMilliseconds)
46+
.round());
47+
48+
final offset = value.position - currentPosition;
49+
50+
useValueChanged(
51+
value.position,
52+
(_, __) {
53+
final correct = value.isPlaying &&
54+
offset.inMilliseconds > -500 &&
55+
offset.inMilliseconds < -50;
56+
final correction = const Duration(milliseconds: 500) - offset;
57+
final targetPos =
58+
correct ? animationController.value : targetRelativePosition;
59+
final duration = correct ? value.duration + correction : value.duration;
60+
61+
animationController.duration = duration;
62+
value.isPlaying
63+
? animationController.forward(from: targetPos)
64+
: animationController.value = targetRelativePosition;
65+
return true;
66+
},
67+
);
68+
69+
useValueChanged(
70+
value.isPlaying,
71+
(_, __) => value.isPlaying
72+
? animationController.forward(from: targetRelativePosition)
73+
: animationController.stop(),
74+
);
75+
76+
return AnimatedBuilder(
77+
animation: animationController,
78+
builder: (context, child) {
79+
final millis =
80+
animationController.value * value.duration.inMilliseconds;
81+
return builder(
82+
context,
83+
Duration(milliseconds: millis.round()),
84+
value.duration,
85+
child,
86+
);
87+
},
88+
child: child,
89+
);
90+
}
91+
}

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ dependencies:
1111

1212
flutter:
1313
sdk: flutter
14-
cached_network_image: ^3.3.1
15-
flutter_cache_manager: ^3.3.2
16-
smooth_video_progress: ^0.0.4
17-
video_player: ^2.8.7
14+
cached_network_image: ^3.4.0
15+
flutter_cache_manager: ^3.4.0
16+
flutter_hooks: ^0.20.5
17+
video_player: ^2.9.1
1818
flutter_inappwebview: ^6.0.0
1919

2020
dev_dependencies:

0 commit comments

Comments
 (0)