builder_VideoArea method

Widget builder_VideoArea(
  1. List? liVideo,
  2. XFDataItem? xclItem
)

Implementation

Widget builder_VideoArea(List<dynamic>? liVideo, XFDataItem? xclItem) {
  return Container(
      margin: EdgeInsets.only(bottom: 7),
      child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: Row(
              children: liVideo!.where((element) => element.xDocID == xclItem!.id).map((element) {
            return GestureDetector(
              onTap: () async {
                // var res = appServices.get
                File x = await File.fromUri(Uri.parse(element.blobURL!));
                VideoPlayerController? videoPlayerController = await VideoPlayerController.file(x);
                bool _isPlaying = false;
                Future<void> _playVideo() async {
                  await videoPlayerController.play();
                  setState(() {});
                }

                Future<void> _pauseVideo() async {
                  await videoPlayerController.pause();
                  setState(() {});
                }

                Future<void> _stopVideo() async {
                  await videoPlayerController.pause();
                  await videoPlayerController.seekTo(Duration.zero);
                  setState(() {});
                }

                return showDialog(
                    context: context,
                    builder: (context) {
                      videoPlayerController
                        ..addListener(() {
                          final bool isPlaying = videoPlayerController.value.isPlaying;
                          if (isPlaying != _isPlaying) {
                            setState(() {
                              _isPlaying = isPlaying;
                            });
                          }
                        })
                        ..initialize().then((_) {
                          setState(() {});
                        });
                      var i;

                      i = liVideo.firstWhereOrNull((element) => element.xDocID == element.id) != null;

                      return XAlertDialog(
                        content_insetPadding: EdgeInsets.all(0),
                        title_TextAlign: TextAlign.center,
                        title_Text: i != null ? "Video del Lavoro" : "Video del Dettaglio",
                        actionsBTNarea_Child: Row(
                          children: [
                            Expanded(
                                child: XBtnbase(
                              label: "Pausa",
                              onPressed: () => _pauseVideo(),
                              label_Style: XStyles.xStyTextForLabel(Colors.yellow),
                            )),
                            Expanded(
                                child: XBtnbase(
                              label: "Play",
                              onPressed: () => _playVideo(),
                              label_Style: XStyles.xStyTextForLabel(Colors.green),
                            ))
                          ],
                        ),
                        child: Stack(
                          children: [Container(width: MediaQuery.of(context).size.width - 10, child: VideoPlayer(videoPlayerController))],
                        ),
                      );
                    }).then((value) {
                  videoPlayerController.dispose();
                });
              },
              child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 5),
                  decoration: BoxDecoration(color: Colors.grey[800], image: DecorationImage(image: MemoryImage(element.miniatura!))),
                  width: 100,
                  height: 100,
                  child: Container(
                    child: Icon(Icons.play_arrow, size: 28),
                  )),
            );
          }).toList())));
}