You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

104 lines
2.8 KiB

import 'package:better_player/better_player.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:teso/Classes/API%20Clasess/CouponDetails.dart';
import 'package:teso/Classes/API%20Clasess/Post.dart';
import 'package:teso/Pages/Sub_Pages/ProductDetails/CouponList.dart';
import 'package:teso/providers/user_provider.dart';
const ASPECT_RATIO = 16 / 9;
class VideoPlayerWidget extends StatefulWidget {
final BetterPlayerController controller;
final Post ad;
final bool play;
final List<CouponDetails> details;
const VideoPlayerWidget({
Key key,
@required this.controller,
@required this.ad,
@required this.play,
this.details,
}) : assert(controller != null),
assert(ad != null),
super(key: key);
@override
_VideoPlayerWidgetState createState() => _VideoPlayerWidgetState();
}
class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {
bool displayed = false;
@override
void initState() {
widget.controller.videoPlayerController.addListener(() => checkVideo());
super.initState();
// if (widget.play) {
// _chewieController.play();
// }
}
checkVideo() async {
// Implement your calls inside these conditions' bodies :
if (widget.controller.videoPlayerController.value.position ==
Duration(seconds: 0, minutes: 0, hours: 0)) {
// print('video Started');
Provider.of<UserProvider>(context, listen: false).viewPost(widget.ad);
}
if (widget.controller.videoPlayerController.value.position.inSeconds >
(widget.controller.videoPlayerController.value.duration.inSeconds) /
3) {
// print('video Ended');
if (!displayed && widget.details.length > 0) {
setState(() {
displayed = true;
});
await Navigator.of(context).push(
PageRouteBuilder(
opaque: false,
pageBuilder: (_, __, ___) => CouponList(
couponsList: widget.details,
),
),
);
}
// _chewieController.play();
}
}
// @override
// void didUpdateWidget(VideoPlayerWidget oldWidget) {
// if (oldWidget.play != widget.play) {
// if (widget.play) {
// _chewieController.play();
// } else {
// _chewieController.pause();
// }
// }
// super.didUpdateWidget(oldWidget);
// }
@override
Widget build(BuildContext context) {
return FittedBox(
clipBehavior: Clip.hardEdge,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: BetterPlayer(
controller: widget.controller,
),
),
);
}
@override
void dispose() {
widget.controller.dispose();
super.dispose();
}
}