123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- import 'dart:async';
- import 'dart:io';
- import 'package:android_intent/android_intent.dart';
- import 'package:device_apps/device_apps.dart';
- import 'package:flutter/material.dart';
- import 'package:sport/bean/feed_back.dart';
- import 'package:sport/bean/game.dart';
- import 'package:sport/pages/my/feedback_detail_page.dart';
- import 'package:sport/pages/web/web_page.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/game_manager.dart';
- import 'package:sport/sharesdk/wechat.dart';
- import 'package:sport/utils/DateFormat.dart';
- import 'package:sport/utils/toast.dart';
- import 'package:sport/widgets/dialog/alert_dialog.dart';
- import 'package:sport/widgets/dialog/request_dialog.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/misc.dart';
- import 'package:sport/widgets/popmenu_bg.dart';
- import 'package:video_player/video_player.dart';
- class GameDetailsVideo extends StatefulWidget {
- final Function changeIsFullScreen;
- final bool _isFullScreen;
- final VideoPlayerController controller;
- bool isLoading;
- final GameInfoData data;
- GameDetailsVideo(this.changeIsFullScreen, this._isFullScreen, this.controller, this.isLoading, this.data, {Key? key}) : super(key: key);
- @override
- State<StatefulWidget> createState() {
- return _GameDetailsVideoState();
- }
- }
- class _GameDetailsVideoState extends State<GameDetailsVideo> with WechatMixin, InjectLoginApi {
- void changeIsFullScreen;
- Timer? timer;
- var opacity = 1.0;
- late VoidCallback _listener;
- ValueNotifier<Duration> timeEnd = ValueNotifier(Duration()); // 播放的时间
- ValueNotifier<Duration> timeStart = ValueNotifier(Duration()); //
- bool isPlaying = false;
- @override
- void initState() {
- super.initState();
- widget.controller.addListener(_listener = () {
- if (!mounted) return;
- timeStart.value = widget.controller.value.position;
- timeEnd.value = widget.controller.value.duration;
- setState(() {
- isPlaying = widget.controller.value.isPlaying;
- });
- });
- }
- @override
- void dispose() {
- super.dispose();
- timer?.cancel();
- widget.controller.removeListener(_listener);
- timeStart.dispose();
- timeEnd.dispose();
- }
- void initdelay() {
- if (timer != null) {
- timer!.cancel();
- }
- setState(() {
- opacity = 1;
- });
- timer = Timer(new Duration(seconds: 3), () {
- setState(() {
- if (mounted) opacity = 0;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- bool isLoading = widget.isLoading;
- VideoPlayerController controller = widget.controller;
- Widget body = Stack(
- children: <Widget>[
- isLoading == false
- ? InkWell(
- child: Center(child: AspectRatio(aspectRatio: controller.value.aspectRatio,child: (VideoPlayer(controller)))),
- onTap: () {
- initdelay();
- },
- onDoubleTap: () {
- if (isPlaying) {
- controller.pause();
- isPlaying = false;
- } else {
- controller.play();
- }
- },
- )
- : Center(child: CircularProgressIndicator()),
- isPlaying != true && isLoading == false
- ? Container(
- width: double.infinity,
- height: double.infinity,
- color: Colors.black45,
- child: Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- SizedBox(
- height: 20,
- ),
- InkWell(
- child: Center(
- child: Image.asset(
- "lib/assets/img/game_icon_play.png",
- width: 50,
- height: 50,
- )),
- onTap: () async {
- if (isPlaying) {
- controller.pause();
- } else {
- if (controller.value.position.compareTo(controller.value.duration) == 0) {
- controller.seekTo(Duration.zero);
- } else {
- initdelay();
- }
- controller.play();
- }
- },
- ),
- SizedBox(
- height: 5,
- ),
- Text(
- "运动演示",
- style: TextStyle(color: Colors.white, fontSize: 14.0),
- ),
- ],
- ),
- ),
- )
- : Container(),
- if (widget._isFullScreen == true)
- Positioned(
- left: 0,
- right: 0,
- child: AnimatedOpacity(
- duration: new Duration(seconds: 1),
- opacity: opacity,
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 0),
- // color: Colors.red,
- decoration: BoxDecoration(
- gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [
- Color(0xFF000000).withOpacity(.5),
- Color(0x00000000)
- // Color(0x00000000),
- ])),
- child: SafeArea(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- IconButton(
- onPressed: () {
- if (widget._isFullScreen) {
- widget.changeIsFullScreen();
- } else {
- // 原生的返回上一页?
- Navigator.pop(context);
- }
- },
- icon: Image.asset(
- "lib/assets/img/topbar_return_white.png",
- width: 26,
- height: 38,
- ),
- ),
- ],
- ),
- right: false,
- ),
- ),
- ),
- ),
- if (isPlaying == true)
- widget._isFullScreen == true ? Positioned(
- bottom: 0,
- left: 0,
- right: 0,
- child: AnimatedOpacity(
- duration: new Duration(seconds: 1),
- opacity: opacity,
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 8),
- decoration: BoxDecoration(
- gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [
- Color(0x00000000), Color(0xFF000000).withOpacity(.5)
- // Color(0x00000000),
- ])),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Row(
- // mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- InkWell(
- child: isPlaying != true
- ? Image.asset(
- "lib/assets/img/gamevideo_play_white.png",
- width: 26,
- height: 38,
- )
- : Image.asset(
- "lib/assets/img/gamevideo_suspend.png",
- width: 26,
- height: 38,
- ),
- onTap: () {
- if (isPlaying) {
- controller.pause();
- } else {
- if (controller.value.position.compareTo(controller.value.duration) == 0) {
- controller.seekTo(Duration.zero);
- } else {
- initdelay();
- }
- controller.play();
- }
- },
- ),
- Padding(
- padding: EdgeInsets.symmetric(horizontal: 5.0),
- child: ValueListenableBuilder<Duration>(
- valueListenable: timeStart,
- builder: (_, v, __) {
- int second = v.inSeconds;
- return Text(DateFormat.toTime(second), style: TextStyle(color: Colors.white));
- }),
- ),
- Expanded(
- child: SizedBox(
- height: 3,
- child: VideoProgressIndicator(controller,
- allowScrubbing: true, // 是否可以拖动
- padding: const EdgeInsets.all(0),
- colors: VideoProgressColors(playedColor: Theme.of(context).accentColor))),
- ),
- Padding(
- padding: EdgeInsets.symmetric(horizontal: 5.0),
- child: ValueListenableBuilder<Duration>(
- valueListenable: timeEnd,
- builder: (_, v, __) {
- int second = v.inSeconds;
- return Text(DateFormat.toTime(second), style: TextStyle(color: Colors.white));
- }),
- ),
- InkWell(
- // 全屏按钮
- child: Image.asset(
- "lib/assets/img/gamevideo_fullscreen.png",
- width: 26,
- height: 38,
- ),
- onTap: () {
- widget.changeIsFullScreen();
- })
- ],
- ),
- ],
- ),
- ),
- ),
- ):Positioned(
- bottom: 0,
- left: 0,
- right: 0,
- child: AnimatedOpacity(
- duration: new Duration(seconds: 1),
- opacity: opacity,
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 8),
- // decoration: BoxDecoration(
- // gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [
- // Color(0x00000000), Color(0xFF000000).withOpacity(.5)
- // // Color(0x00000000),
- // ])),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Row(
- // mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- // InkWell(
- // child: isPlaying != true
- // ? Image.asset(
- // "lib/assets/img/gamevideo_play_white.png",
- // width: 26,
- // height: 38,
- // )
- // : Image.asset(
- // "lib/assets/img/gamevideo_suspend.png",
- // width: 26,
- // height: 38,
- // ),
- // onTap: () {
- // if (isPlaying) {
- // controller.pause();
- // } else {
- // if (controller.value.position.compareTo(controller.value.duration) == 0) {
- // controller.seekTo(Duration.zero);
- // } else {
- // initdelay();
- // }
- // controller.play();
- // }
- // },
- // ),
- // Padding(
- // padding: EdgeInsets.symmetric(horizontal: 5.0),
- // child: ValueListenableBuilder<Duration>(
- // valueListenable: timeStart,
- // builder: (_, v, __) {
- // int second = v.inSeconds;
- // return Text(DateFormat.toTime(second), style: TextStyle(color: Colors.white));
- // }),
- // ),
- // Expanded(
- // child: SizedBox(
- // height: 3,
- // child: VideoProgressIndicator(controller,
- // allowScrubbing: true, // 是否可以拖动
- // padding: const EdgeInsets.all(0),
- // colors: VideoProgressColors(playedColor: Theme.of(context).accentColor))),
- // ),
- // Padding(
- // padding: EdgeInsets.symmetric(horizontal: 5.0),
- // child: ValueListenableBuilder<Duration>(
- // valueListenable: timeEnd,
- // builder: (_, v, __) {
- // int second = v.inSeconds;
- // return Text(DateFormat.toTime(second), style: TextStyle(color: Colors.white));
- // }),
- // ),
- InkWell(
- // 全屏按钮
- child: Image.asset(
- "lib/assets/img/gamevideo_fullscreen.png",
- width: 26,
- height: 38,
- ),
- onTap: () {
- widget.changeIsFullScreen();
- })
- ],
- ),
- ],
- ),
- ),
- ),
- ),
- // ClosedCaption(text: _controller.value.caption.text),
- ],
- );
- return Container(
- color: Colors.black,
- // 约束宽高的
- child: widget._isFullScreen
- ? body
- : AspectRatio(
- aspectRatio: 1.78,
- child: body,
- ));
- }
- _onPopMenuSelected(var val) async {
- switch (val) {
- case '运动记录':
- NavigatorUtil.goGameHistory(context, widget.data);
- break;
- case '操作指引':
- NavigatorUtil.goPage(context, (context) => WebPage(url: "http://xie-web.hiyd.com/index.html#/game_guide?id=${widget.data.id}"));
- break;
- case '问题反馈':
- FeedTypeInfoData? group;
- await request(context, () async {
- FeedTypeInfo _feedTypeInfo = await loginApi.getFeedBackTypes();
- if (_feedTypeInfo.code == 0) {
- group = _feedTypeInfo.data?.singleWhere((element) => element.groupId == '3');
- }
- });
- if (group != null) {
- NavigatorUtil.goPage(context, (context) => FeedbackDetailPage(group!));
- }
- break;
- case '删除运动':
- if (Platform.isAndroid) {
- var installed = await DeviceApps.isAppInstalled(widget.data.packageNameAndroid ?? "");
- if (installed == true) {
- if (await showDialog(
- context: context,
- builder: (context) => CustomAlertDialog(title: '是否删除运动', ok: () => Navigator.of(context).pop(true)),
- ) ==
- true) {
- GameManager.deleteFile(widget.data);
- if (Platform.isAndroid) {
- AndroidIntent intent = AndroidIntent(
- action: 'android.intent.action.DELETE',
- data: 'package:${widget.data.packageNameAndroid}',
- );
- await intent.launch();
- setState(() {});
- }
- }
- } else {}
- }
- break;
- }
- }
- }
|