flutter_camera_demo icon indicating copy to clipboard operation
flutter_camera_demo copied to clipboard

PreviewScreen throws error "Null check operator used on a null value" when opening video

Open sreenath-n opened this issue 3 years ago • 3 comments

PreviewScreen widget doesn't support video. So it throws the error "Null check operator used on a null value" when trying to open video.

sreenath-n avatar Jul 07 '22 10:07 sreenath-n

@sreenath-n yes same issue , and when we move "Go to all capture" button , we are able to see only images which are we capture previously not videos. Means that we neither be able to record video nor be able to save it. Can you find any solution regarding this issue then please comment !!

@sbis04 Please note this issue.

vaidarbhi01 avatar Sep 14 '22 07:09 vaidarbhi01

same. anyone available to fix?

cmptscpeacock avatar Aug 15 '23 08:08 cmptscpeacock

Put an if statement in. Not sure if this is the right approach but it works, so it'll do for now:


InkWell(
                                        onTap: _isVideoCameraSelected
                                            ? () async {
                                                if (_isRecordingInProgress) {
                                                  XFile? rawVideo =
                                                      await stopVideoRecording();
                                                  File videoFile =
                                                      File(rawVideo!.path);

                                                  int currentUnix = DateTime
                                                          .now()
                                                      .millisecondsSinceEpoch;

                                                  final directory =
                                                      await getApplicationDocumentsDirectory();

                                                  String fileFormat = videoFile
                                                      .path
                                                      .split('.')
                                                      .last;

                                                  _videoFile =
                                                      await videoFile.copy(
                                                    '${directory.path}/$currentUnix.$fileFormat',
                                                  );

                                                  // #bug1 _startVideoPlayer();
                                                } else {
                                                  await startVideoRecording();
                                                }
                                              }
                                            : () async {
                                                XFile? rawImage =
                                                    await takePicture();

                                                if (rawImage != null) {
                                                  File imageFile =
                                                      File(rawImage.path);

                                                  int currentUnix = DateTime
                                                          .now()
                                                      .millisecondsSinceEpoch;

                                                  final directory =
                                                      await getApplicationDocumentsDirectory();

                                                  String fileFormat = imageFile
                                                      .path
                                                      .split('.')
                                                      .last;

                                                  print(fileFormat);

                                                  await imageFile.copy(
                                                    '${directory.path}/$currentUnix.$fileFormat',
                                                  );
                                                } else {}

                                                refreshAlreadyCapturedImages();
                                              },
                                        child: Stack(
                                          alignment: Alignment.center,
                                          children: [
                                            Icon(
                                              Icons.circle,
                                              color: _isVideoCameraSelected
                                                  ? Colors.white
                                                  : Colors.white38,
                                              size: 80,
                                            ),
                                            Icon(
                                              Icons.circle,
                                              color: _isVideoCameraSelected
                                                  ? Colors.red
                                                  : Colors.white,
                                              size: 65,
                                            ),
                                            _isVideoCameraSelected &&
                                                    _isRecordingInProgress
                                                ? Icon(
                                                    Icons.stop_rounded,
                                                    color: Colors.white,
                                                    size: 32,
                                                  )
                                                : Container(),
                                          ],
                                        ),
                                      ),

cmptscpeacock avatar Aug 15 '23 18:08 cmptscpeacock