Skip to content

Commit 7f28979

Browse files
committed
🚀 Sync video preview layouts for WeChat Moment
1 parent 73c8755 commit 7f28979

File tree

2 files changed

+81
-29
lines changed

2 files changed

+81
-29
lines changed

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ class DefaultAssetPickerViewerBuilderDelegate
348348
);
349349
break;
350350
case AssetType.video:
351-
builder = VideoPageBuilder(asset: asset, state: viewerState);
351+
builder = VideoPageBuilder(
352+
asset: asset,
353+
state: viewerState,
354+
hasOnlyOneVideoAndMoment: isWeChatMoment && hasVideo,
355+
);
352356
break;
353357
case AssetType.other:
354358
builder = Center(
@@ -399,6 +403,30 @@ class DefaultAssetPickerViewerBuilderDelegate
399403
);
400404
}
401405

406+
/// The back button when previewing video in [SpecialPickerType.wechatMoment].
407+
/// 使用 [SpecialPickerType.wechatMoment] 预览视频时的返回按钮
408+
Widget momentVideoBackButton(BuildContext context) {
409+
return PositionedDirectional(
410+
start: 16,
411+
top: context.mediaQuery.padding.top + 16,
412+
child: GestureDetector(
413+
onTap: Navigator.of(context).maybePop,
414+
child: Container(
415+
padding: const EdgeInsets.all(5),
416+
decoration: BoxDecoration(
417+
color: themeData.iconTheme.color,
418+
shape: BoxShape.circle,
419+
),
420+
child: Icon(
421+
Icons.keyboard_return_rounded,
422+
color: themeData.canvasColor,
423+
size: 18,
424+
),
425+
),
426+
),
427+
);
428+
}
429+
402430
@override
403431
Widget bottomDetailBuilder(BuildContext context) {
404432
final Color _backgroundColor = themeData.primaryColor.withOpacity(.9);
@@ -790,9 +818,19 @@ class DefaultAssetPickerViewerBuilderDelegate
790818
scrollDirection: Axis.horizontal,
791819
),
792820
),
793-
appBar(context),
794-
if (selectedAssets != null || (isWeChatMoment && hasVideo))
795-
bottomDetailBuilder(context),
821+
if (isWeChatMoment && hasVideo) ...<Widget>[
822+
momentVideoBackButton(context),
823+
PositionedDirectional(
824+
end: 16,
825+
bottom: context.mediaQuery.padding.bottom + 16,
826+
child: confirmButton(context),
827+
),
828+
] else ...<Widget>[
829+
appBar(context),
830+
if (selectedAssets != null ||
831+
(isWeChatMoment && hasVideo && isAppleOS))
832+
bottomDetailBuilder(context),
833+
],
796834
],
797835
),
798836
),

lib/src/widget/builder/video_page_builder.dart

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ class VideoPageBuilder extends StatefulWidget {
1212
Key? key,
1313
required this.asset,
1414
required this.state,
15+
this.hasOnlyOneVideoAndMoment = false,
1516
}) : super(key: key);
1617

1718
/// Asset currently displayed.
1819
/// 展示的资源
1920
final AssetEntity asset;
2021

2122
/// [State] for asset picker viewer.
22-
/// 资源查看器的状态[State]
23+
/// 资源查看器的状态 [State]
2324
final AssetPickerViewerState<AssetEntity, AssetPathEntity> state;
2425

26+
/// Only previewing one video and with the [SpecialPickerType.wechatMoment].
27+
/// 是否处于 [SpecialPickerType.wechatMoment] 且只有一个视频
28+
final bool hasOnlyOneVideoAndMoment;
29+
2530
@override
2631
_VideoPageBuilderState createState() => _VideoPageBuilderState();
2732
}
@@ -81,7 +86,12 @@ class _VideoPageBuilderState extends State<VideoPageBuilder> {
8186
try {
8287
await _controller.initialize();
8388
hasLoaded = true;
84-
_controller.addListener(videoPlayerListener);
89+
_controller
90+
..addListener(videoPlayerListener)
91+
..setLooping(widget.hasOnlyOneVideoAndMoment);
92+
if (widget.hasOnlyOneVideoAndMoment) {
93+
_controller.play();
94+
}
8595
} catch (e) {
8696
realDebugPrint('Error when initialize video controller: $e');
8797
hasErrorWhenInitializing = true;
@@ -142,35 +152,39 @@ class _VideoPageBuilderState extends State<VideoPageBuilder> {
142152
),
143153
),
144154
),
145-
ValueListenableBuilder<bool>(
146-
valueListenable: isPlaying,
147-
builder: (_, bool value, __) => GestureDetector(
148-
behavior: HitTestBehavior.opaque,
149-
onTap: value ? playButtonCallback : builder.switchDisplayingDetail,
150-
child: Center(
151-
child: AnimatedOpacity(
152-
duration: kThemeAnimationDuration,
153-
opacity: value ? 0.0 : 1.0,
154-
child: GestureDetector(
155-
onTap: playButtonCallback,
156-
child: DecoratedBox(
157-
decoration: const BoxDecoration(
158-
boxShadow: <BoxShadow>[BoxShadow(color: Colors.black12)],
159-
shape: BoxShape.circle,
160-
),
161-
child: Icon(
162-
value
163-
? Icons.pause_circle_outline
164-
: Icons.play_circle_filled,
165-
size: 70.0,
166-
color: Colors.white,
155+
if (!widget.hasOnlyOneVideoAndMoment)
156+
ValueListenableBuilder<bool>(
157+
valueListenable: isPlaying,
158+
builder: (_, bool value, __) => GestureDetector(
159+
behavior: HitTestBehavior.opaque,
160+
onTap:
161+
value ? playButtonCallback : builder.switchDisplayingDetail,
162+
child: Center(
163+
child: AnimatedOpacity(
164+
duration: kThemeAnimationDuration,
165+
opacity: value ? 0.0 : 1.0,
166+
child: GestureDetector(
167+
onTap: playButtonCallback,
168+
child: DecoratedBox(
169+
decoration: const BoxDecoration(
170+
boxShadow: <BoxShadow>[
171+
BoxShadow(color: Colors.black12)
172+
],
173+
shape: BoxShape.circle,
174+
),
175+
child: Icon(
176+
value
177+
? Icons.pause_circle_outline
178+
: Icons.play_circle_filled,
179+
size: 70.0,
180+
color: Colors.white,
181+
),
167182
),
168183
),
169184
),
170185
),
171186
),
172187
),
173-
),
174188
],
175189
);
176190
}

0 commit comments

Comments
 (0)