Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Commit

Permalink
修复退出全屏时bug
Browse files Browse the repository at this point in the history
  • Loading branch information
januwA committed Jun 22, 2019
1 parent a642ae3 commit 1f2f059
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
62 changes: 41 additions & 21 deletions lib/shared/widgets/video_box/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import 'package:video_player/video_player.dart';

/// video+controller 容器盒子
class VideoBox extends StatefulWidget {
VideoBox({Key key, this.src, this.store}) : super(key: key);
VideoBox({
Key key,

/// 网络播放地址
this.src,
this.store,
this.isDispose = true,
}) : super(key: key);

final String src;
final VideoStore store;

final bool isDispose;
@override
_VideoBoxState createState() => _VideoBoxState();
}
Expand All @@ -27,7 +34,9 @@ class _VideoBoxState extends State<VideoBox> {

@override
void dispose() {
videoStore.dispose();
if (widget.isDispose) {
videoStore.dispose();
}
super.dispose();
}

Expand Down Expand Up @@ -156,28 +165,20 @@ class VideoBottomCtrl extends StatelessWidget {
),
onPressed: () async {
if (videoStore.isFullScreen) {
/// 退出全屏
Navigator.of(context).pop();
videoStore.setPortrait();
} else {
/// 开启全屏
/// 改变屏幕方向,不销毁控制器
videoStore.setLandscape();
final result = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return SafeArea(
child: Scaffold(
body: VideoBox(
src: videoStore.src,
store: videoStore,
),
),
);
},
),
);
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => FullScreenVideo(
videoStore: videoStore,
)));

if (result == null) {
videoStore.setPortrait();
}
/// 用户结束了全屏
/// 按下icon或者手机返回键
videoStore.setPortrait();
}
},
),
Expand Down Expand Up @@ -222,3 +223,22 @@ class VideoLoading extends StatelessWidget {
);
}
}

/// 全屏播放view
class FullScreenVideo extends StatelessWidget {
FullScreenVideo({this.videoStore});
final VideoStore videoStore;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: VideoBox(
store: videoStore,
isDispose: false,
),
),
),
);
}
}
3 changes: 0 additions & 3 deletions lib/shared/widgets/video_box/video.store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ abstract class _VideoStore with Store {
videoCtrl?.removeListener(videoListenner);
videoCtrl?.pause();
videoCtrl?.dispose();
if (isFullScreen) {
setPortrait();
}
super.dispose();
}
}

0 comments on commit 1f2f059

Please sign in to comment.