mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 07:02:12 +00:00
using user stream builder for user changes
This commit is contained in:
parent
dde339d1b3
commit
f8649298e0
1 changed files with 143 additions and 136 deletions
|
|
@ -209,13 +209,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
|
|
||||||
if (!_hasAudioPermission &&
|
if (!_hasAudioPermission &&
|
||||||
!userService.currentUser.requestedAudioPermission) {
|
!userService.currentUser.requestedAudioPermission) {
|
||||||
await updateUser((u) {
|
await updateUser((u) => u.requestedAudioPermission = true);
|
||||||
u.requestedAudioPermission = true;
|
|
||||||
});
|
|
||||||
await requestMicrophonePermission();
|
await requestMicrophonePermission();
|
||||||
}
|
}
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> requestMicrophonePermission() async {
|
Future<void> requestMicrophonePermission() async {
|
||||||
|
|
@ -226,7 +222,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
await openAppSettings();
|
await openAppSettings();
|
||||||
} else {
|
} else {
|
||||||
_hasAudioPermission = await Permission.microphone.isGranted;
|
_hasAudioPermission = await Permission.microphone.isGranted;
|
||||||
setState(() {});
|
setState(() {
|
||||||
|
// _hasAudioPermission
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,18 +399,16 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.selectedCameraDetails.scaleFactor =
|
setState(() {
|
||||||
(_baseScaleFactor +
|
mc.selectedCameraDetails.scaleFactor =
|
||||||
// ignore: avoid_dynamic_calls
|
(_baseScaleFactor +
|
||||||
(_basePanY - (details.localPosition.dy as double)) / 30)
|
// ignore: avoid_dynamic_calls
|
||||||
.clamp(1, mc.selectedCameraDetails.maxAvailableZoom);
|
(_basePanY - (details.localPosition.dy as double)) / 30)
|
||||||
|
.clamp(1, mc.selectedCameraDetails.maxAvailableZoom);
|
||||||
|
});
|
||||||
await mc.cameraController!.setZoomLevel(
|
await mc.cameraController!.setZoomLevel(
|
||||||
mc.selectedCameraDetails.scaleFactor,
|
mc.selectedCameraDetails.scaleFactor,
|
||||||
);
|
);
|
||||||
if (mounted) {
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pickImageFromGallery() async {
|
Future<void> pickImageFromGallery() async {
|
||||||
|
|
@ -597,132 +593,143 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
mc.cameraController == null) {
|
mc.cameraController == null) {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
// TODO: STREAM BUILDER FOR GlOBAL USER CHANGES
|
return StreamBuilder(
|
||||||
return MediaViewSizingHelper(
|
stream: userService.onUserUpdated,
|
||||||
requiredHeight: 0,
|
builder: (context, asyncSnapshot) {
|
||||||
additionalPadding: 59,
|
return MediaViewSizingHelper(
|
||||||
bottomNavigation: Container(),
|
requiredHeight: 0,
|
||||||
child: GestureDetector(
|
additionalPadding: 59,
|
||||||
onPanStart: (details) async {
|
bottomNavigation: Container(),
|
||||||
setState(() {
|
child: GestureDetector(
|
||||||
_basePanY = details.localPosition.dy;
|
onPanStart: (details) async {
|
||||||
_baseScaleFactor = mc.selectedCameraDetails.scaleFactor;
|
setState(() {
|
||||||
});
|
_basePanY = details.localPosition.dy;
|
||||||
},
|
_baseScaleFactor = mc.selectedCameraDetails.scaleFactor;
|
||||||
onLongPressMoveUpdate: onPanUpdate,
|
});
|
||||||
onLongPressStart: (details) {
|
},
|
||||||
setState(() {
|
onLongPressMoveUpdate: onPanUpdate,
|
||||||
_basePanY = details.localPosition.dy;
|
onLongPressStart: (details) {
|
||||||
_baseScaleFactor = mc.selectedCameraDetails.scaleFactor;
|
setState(() {
|
||||||
});
|
_basePanY = details.localPosition.dy;
|
||||||
// Get the position of the pointer
|
_baseScaleFactor = mc.selectedCameraDetails.scaleFactor;
|
||||||
final renderBox =
|
});
|
||||||
keyTriggerButton.currentContext!.findRenderObject()! as RenderBox;
|
// Get the position of the pointer
|
||||||
final localPosition = renderBox.globalToLocal(details.globalPosition);
|
final renderBox =
|
||||||
|
keyTriggerButton.currentContext!.findRenderObject()!
|
||||||
|
as RenderBox;
|
||||||
|
final localPosition = renderBox.globalToLocal(
|
||||||
|
details.globalPosition,
|
||||||
|
);
|
||||||
|
|
||||||
final containerRect = Rect.fromLTWH(
|
final containerRect = Rect.fromLTWH(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
renderBox.size.width,
|
renderBox.size.width,
|
||||||
renderBox.size.height,
|
renderBox.size.height,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (containerRect.contains(localPosition)) {
|
if (containerRect.contains(localPosition)) {
|
||||||
startVideoRecording();
|
startVideoRecording();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPressEnd: (a) {
|
onLongPressEnd: (a) {
|
||||||
stopVideoRecording();
|
stopVideoRecording();
|
||||||
},
|
},
|
||||||
onPanEnd: (a) {
|
onPanEnd: (a) {
|
||||||
stopVideoRecording();
|
stopVideoRecording();
|
||||||
},
|
},
|
||||||
onPanUpdate: onPanUpdate,
|
onPanUpdate: onPanUpdate,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
if (_galleryLoadedImageIsShown)
|
if (_galleryLoadedImageIsShown)
|
||||||
Center(
|
Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 60,
|
height: 60,
|
||||||
width: 60,
|
width: 60,
|
||||||
child: ThreeRotatingDots(
|
child: ThreeRotatingDots(
|
||||||
size: 40,
|
size: 40,
|
||||||
color: context.color.primary,
|
color: context.color.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
if (!mc.isSharePreviewIsShown &&
|
||||||
|
widget.sendToGroup != null &&
|
||||||
|
!mc.isVideoRecording)
|
||||||
|
ShowTitleText(
|
||||||
|
title: widget.sendToGroup!.groupName,
|
||||||
|
desc: context.lang.cameraPreviewSendTo,
|
||||||
|
),
|
||||||
|
if (!mc.isSharePreviewIsShown &&
|
||||||
|
mc.sharedLinkForPreview != null &&
|
||||||
|
!mc.isVideoRecording)
|
||||||
|
ShowTitleText(
|
||||||
|
title: mc.sharedLinkForPreview?.host ?? '',
|
||||||
|
desc: 'Link',
|
||||||
|
isLink: true,
|
||||||
|
),
|
||||||
|
if (!mc.isSharePreviewIsShown &&
|
||||||
|
!mc.isVideoRecording &&
|
||||||
|
!widget.hideControllers)
|
||||||
|
CameraTopActions(
|
||||||
|
selectedCameraDetails: mc.selectedCameraDetails,
|
||||||
|
hasAudioPermission: _hasAudioPermission,
|
||||||
|
onSwitchCamera: () async {
|
||||||
|
await mc.selectCamera(
|
||||||
|
(mc.selectedCameraDetails.cameraId + 1) % 2,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onToggleFlash: () async {
|
||||||
|
if (mc.selectedCameraDetails.isFlashOn) {
|
||||||
|
await mc.cameraController?.setFlashMode(FlashMode.off);
|
||||||
|
mc.selectedCameraDetails.isFlashOn = false;
|
||||||
|
} else {
|
||||||
|
await mc.cameraController?.setFlashMode(
|
||||||
|
FlashMode.always,
|
||||||
|
);
|
||||||
|
mc.selectedCameraDetails.isFlashOn = true;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
// mc.selectedCameraDetails.isFlashOn
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onRequestMicrophone: requestMicrophonePermission,
|
||||||
|
),
|
||||||
|
if (!mc.isSharePreviewIsShown && !widget.hideControllers)
|
||||||
|
CameraBottomControls(
|
||||||
|
mainController: mc,
|
||||||
|
isVideoRecording: mc.isVideoRecording,
|
||||||
|
isFront: isFront,
|
||||||
|
keyTriggerButton: keyTriggerButton,
|
||||||
|
onTakePicture: takePicture,
|
||||||
|
onPressSideButtonLeft: pressSideButtonLeft,
|
||||||
|
onPressSideButtonRight: pressSideButtonRight,
|
||||||
|
updateScaleFactor: updateScaleFactor,
|
||||||
|
),
|
||||||
|
VideoRecordingTimer(
|
||||||
|
videoRecordingStarted: _videoRecordingStarted,
|
||||||
|
maxVideoRecordingTime: maxVideoRecordingTime,
|
||||||
),
|
),
|
||||||
),
|
if (!mc.isSharePreviewIsShown && widget.sendToGroup != null ||
|
||||||
if (!mc.isSharePreviewIsShown &&
|
widget.hideControllers)
|
||||||
widget.sendToGroup != null &&
|
Positioned(
|
||||||
!mc.isVideoRecording)
|
left: 5,
|
||||||
ShowTitleText(
|
top: 10,
|
||||||
title: widget.sendToGroup!.groupName,
|
child: ActionButton(
|
||||||
desc: context.lang.cameraPreviewSendTo,
|
FontAwesomeIcons.xmark,
|
||||||
),
|
tooltipText: context.lang.close,
|
||||||
if (!mc.isSharePreviewIsShown &&
|
onPressed: () async {
|
||||||
mc.sharedLinkForPreview != null &&
|
Navigator.pop(context);
|
||||||
!mc.isVideoRecording)
|
},
|
||||||
ShowTitleText(
|
),
|
||||||
title: mc.sharedLinkForPreview?.host ?? '',
|
),
|
||||||
desc: 'Link',
|
if (_showSelfieFlash) const CameraSelfieFlash(),
|
||||||
isLink: true,
|
CameraScannedOverlay(mainController: mc),
|
||||||
),
|
],
|
||||||
if (!mc.isSharePreviewIsShown &&
|
|
||||||
!mc.isVideoRecording &&
|
|
||||||
!widget.hideControllers)
|
|
||||||
CameraTopActions(
|
|
||||||
selectedCameraDetails: mc.selectedCameraDetails,
|
|
||||||
hasAudioPermission: _hasAudioPermission,
|
|
||||||
onSwitchCamera: () async {
|
|
||||||
await mc.selectCamera(
|
|
||||||
(mc.selectedCameraDetails.cameraId + 1) % 2,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onToggleFlash: () async {
|
|
||||||
if (mc.selectedCameraDetails.isFlashOn) {
|
|
||||||
await mc.cameraController?.setFlashMode(FlashMode.off);
|
|
||||||
mc.selectedCameraDetails.isFlashOn = false;
|
|
||||||
} else {
|
|
||||||
await mc.cameraController?.setFlashMode(FlashMode.always);
|
|
||||||
mc.selectedCameraDetails.isFlashOn = true;
|
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
onRequestMicrophone: requestMicrophonePermission,
|
|
||||||
),
|
|
||||||
if (!mc.isSharePreviewIsShown && !widget.hideControllers)
|
|
||||||
CameraBottomControls(
|
|
||||||
mainController: mc,
|
|
||||||
isVideoRecording: mc.isVideoRecording,
|
|
||||||
isFront: isFront,
|
|
||||||
keyTriggerButton: keyTriggerButton,
|
|
||||||
onTakePicture: takePicture,
|
|
||||||
onPressSideButtonLeft: pressSideButtonLeft,
|
|
||||||
onPressSideButtonRight: pressSideButtonRight,
|
|
||||||
updateScaleFactor: updateScaleFactor,
|
|
||||||
),
|
|
||||||
VideoRecordingTimer(
|
|
||||||
videoRecordingStarted: _videoRecordingStarted,
|
|
||||||
maxVideoRecordingTime: maxVideoRecordingTime,
|
|
||||||
),
|
),
|
||||||
if (!mc.isSharePreviewIsShown && widget.sendToGroup != null ||
|
),
|
||||||
widget.hideControllers)
|
);
|
||||||
Positioned(
|
},
|
||||||
left: 5,
|
|
||||||
top: 10,
|
|
||||||
child: ActionButton(
|
|
||||||
FontAwesomeIcons.xmark,
|
|
||||||
tooltipText: context.lang.close,
|
|
||||||
onPressed: () async {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (_showSelfieFlash) const CameraSelfieFlash(),
|
|
||||||
CameraScannedOverlay(mainController: mc),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue