xCMD_GetMedia method

Future<List<XMediaItem>?> xCMD_GetMedia(
  1. void setState(
    1. void ()
    ),
  2. XFDataItem item, {
  3. List<XMediaItem>? liXMedia_UI,
})

Comando per aprire il Widget per la Registrazione degli XMedia

Implementation

Future<List<XMediaItem>?> xCMD_GetMedia(void Function(void Function()) setState, XFDataItem item, {List<XMediaItem>? liXMedia_UI}) async {
  item.isShowDetails = true;
  FocusScope.of(context).unfocus();
  if (liXMedia_UI != null) liXMedias_MediaRecorder.value.addAll(liXMedia_UI);
  if (_cameras.isEmpty) _cameras = await availableCameras();
  widget.xApp!.state.cameras.clear();
  widget.xApp!.state.cameras.addAll(_cameras);
  late CameraController _photoController;
  if (XMediaRecorder.xCurrentCamera == null) {
    XMediaRecorder.xCurrentCamera = (kIsWeb && _cameras.length > 1)
        ? _cameras[1]
        : kIsWeb
            ? _cameras[0]
            : _cameras.length > 1
                ? _cameras[1]
                : _cameras[0];
  }

  await showDialog(
      context: context,
      barrierDismissible: false,
      builder: (builder) {
        return FutureBuilder(future: () async {
          _photoController = CameraController(XMediaRecorder.xCurrentCamera!, ResolutionPreset.medium, enableAudio: true);
          await _photoController.initialize();
          setState(() {});
          return true;
        }(),
            // xApp.app_Name = "Coffee Meeting\n${xclAnag.cognome} ${xclAnag.nome}";
            builder: (context, snapshot) {
          return StatefulBuilder(builder: (context, setStte) {
            return XAlertDialog(
                colorBackGround: Colors.grey[900],
                actionsBTNarea_Padding: EdgeInsets.all(1),
                child: Column(
                  children: [
                    saving
                        ? Container()

                        ///Row delle Preview dei media fatti
                        : Row(mainAxisAlignment: liXMedias_MediaRecorder.value.isNotEmpty ? MainAxisAlignment.start : MainAxisAlignment.center, children: [
                            Expanded(
                                child: SingleChildScrollView(
                                    scrollDirection: Axis.horizontal,
                                    child: Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: liXMedias_MediaRecorder.value.isEmpty
                                            ? [Container(height: 80, width: MediaQuery.of(context).size.width, color: Colors.grey[800], alignment: Alignment.center)]
                                            : liXMedias_MediaRecorder.value
                                                .map((e) => InkWell(
                                                    child: e.mediaType == XEnums.mediaType.image.value
                                                        ? Container(
                                                            width: 80,
                                                            height: 80,
                                                            child: Stack(children: [
                                                              Container(margin: EdgeInsets.symmetric(horizontal: 5), width: 80, child: Image.memory(e.payload!, width: 80, height: 80)),
                                                              e.overlaySurface != null ? Container(margin: EdgeInsets.only(bottom: 50), child: Image.memory(e.overlaySurface!, height: 80, width: 80)) : Container(),
                                                            ]))
                                                        : e.mediaType == XEnums.mediaType.video.value
                                                            ? Container(
                                                                margin: EdgeInsets.symmetric(horizontal: 5),
                                                                decoration: BoxDecoration(color: Colors.grey[800], image: DecorationImage(image: MemoryImage(e.miniatura!))),
                                                                width: 80,
                                                                height: 80,
                                                                child: Container(child: Icon(Icons.play_arrow, size: 28, color: Colors.blueAccent[900])),
                                                              )
                                                            : Container(
                                                                margin: EdgeInsets.symmetric(horizontal: 5),
                                                                decoration: BoxDecoration(color: Colors.grey[800]),
                                                                width: 80,
                                                                height: 80,
                                                                child: Icon(Icons.mic),
                                                              )))
                                                .toList())))
                          ]),
                    Container(
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height / 1.4 : MediaQuery.of(context).size.height / 1.42,
                        child: XMediaRecorder<XFDataItem>(
                          widget.key,
                          parentSetState: setStte,
                          photoController: _photoController,
                          itemOriginal: item,
                          lXMedias: liXMedias_MediaRecorder.value,
                          xApp: widget.xApp!,
                          onStartTakeVideo: (parentState) => setStte(() => isRecording = true),
                          onEndTakeVideo: (parentState) => setStte(() => isRecording = false),
                          onTakeMedia: (parentState) => setStte(() {
                            isTakingPhoto = isTakingPhoto.not();
                          }),
                        )),
                  ],
                ),
                title_Text: "Fotocamera del Lavoro",
                title_Style: XStyles.xStyTextForLabel(textColor: Colors.yellow),
                content_insetPadding: EdgeInsets.all(0),
                actionsBTNarea_Child: Container(
                    height: 70,
                    child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                      isRecording || isTakingPhoto
                          ? Expanded(
                              child: isRecording
                                  ? Text("Sto Registrando...", style: XStyles.xStyTextForSubLabel(textColor: Colors.red), textAlign: TextAlign.center) //
                                  : isTakingPhoto.not()
                                      ? Container()
                                      : XStatefulWidgetBase.LoaderIndicator(isTakingPhoto, label: "Acquisizione Media..", fixHeight: 30, fixWidth: 30))
                          : Container(),
                      isTakingPhoto || isRecording
                          ? Container()
                          : Expanded(
                              child: XBtnbase(
                              height: 45,
                              icon_Widget: Icon(Icons.undo, color: Colors.red, size: 30),
                              backGroundColor: Colors.grey[800]!,
                              elevation: 0,
                              label: "",
                              onPressed: () async {
                                liXMedias_MediaRecorder.value.clear();
                                await _photoController.dispose();
                                Navigator.pop(context, false);
                              },
                            )),
                      SizedBox(width: 6),
                      isTakingPhoto || isRecording
                          ? Container()
                          : Expanded(
                              child: XBtnbase(
                                  label: "Dalla Galleria...",
                                  height: 45,
                                  backGroundColor: Colors.grey[800]!,
                                  elevation: 0,
                                  onPressed: () async {
                                    await _photoController.pausePreview();
                                    await xOnGetXMedia_FromGallery();
                                    if (_images.isNotEmpty) {
                                      _images.forEach((xclFile) async {
                                        print(xclFile.name);
                                        var xMedia = XMediaItem(
                                          Uuid().v4(),
                                          xDocID: item.id,
                                          payload: File(xclFile.path).readAsBytesSync(),
                                          isNew: true,
                                          mediaType: xclFile.name.endsWith("mp4")
                                              ? XEnums.mediaType.video.value
                                              : (xclFile.name.endsWith("jpg") || xclFile.name.endsWith("png") || xclFile.name.endsWith("jpeg"))
                                                  ? XEnums.mediaType.image.value
                                                  : xclFile.name.endsWith("aac")
                                                      ? XEnums.mediaType.audio.value
                                                      : XEnums.mediaType.image.value,
                                        );
                                        if (xMedia.payload != null) {
                                          xMedia.miniatura = await xCreateThumbnails_FromImage(xMedia.payload!);
                                        }
                                        setStte(() => liXMedias_MediaRecorder.value.add(xMedia));
                                      });
                                    }
                                    await _photoController.resumePreview();
                                  })),
                      SizedBox(width: 6),
                      liXMedias_MediaRecorder.value.isNotEmpty
                          ? isTakingPhoto || isRecording
                              ? Container()
                              : Expanded(
                                  child: XBtnbase(
                                      height: 45,
                                      backGroundColor: Colors.grey[900]!,
                                      elevation: 0,
                                      icon_Widget: Icon(Icons.save, color: Colors.green, size: 30),
                                      label_Style: XStyles.xStyleText(colorText: Colors.green, fontSize: 24, activeBold: false),
                                      onPressed: () async {
                                        _photoController.pausePreview();
                                        setStte(() => saving = true);
                                        if (liXMedias_MediaRecorder.value.isNotEmpty) {
                                          isTakingPhoto = true;
                                          await Future.forEach(liXMedias_MediaRecorder.value, (xclMedia) => xMedia_OnTake_Handling(xclMedia.payload!, isBusy, setState, item, xclMedia.mediaType!));
                                          await xMedia_OnSave_INTERNAL(liMediaRAW, item);
                                          item.showXMedia = true;
                                          if (item is T) editedPage.value = true;
                                          widget.key_AppBar = UniqueKey();
                                          widget.key_BottomBar = UniqueKey();
                                          widget.key_Head = UniqueKey();
                                          widget.key_Rows = UniqueKey();
                                          xBottomBarAction_Fill();
                                        }
                                        liXMedias_MediaRecorder.value.clear();
                                        isTakingPhoto = false;
                                        saving = false;
                                        Navigator.pop(context, true);
                                        await _photoController.dispose();
                                      }))
                          : Container()
                    ])));
          });
        });
      });
  return liMediaRAW.isNotEmpty ? liMediaRAW : null;
}