mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 09:08:40 +00:00
fix #246
This commit is contained in:
parent
6d1643848f
commit
9f45a461a2
4 changed files with 54 additions and 26 deletions
|
|
@ -1,21 +1,28 @@
|
|||
// ignore_for_file: avoid_dynamic_calls
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:twonly/globals.dart';
|
||||
import 'package:twonly/src/views/camera/camera_preview_controller_view.dart';
|
||||
|
||||
class CameraZoomButtons extends StatefulWidget {
|
||||
const CameraZoomButtons({
|
||||
required this.controller,
|
||||
required this.updateScaleFactor,
|
||||
required this.scaleFactor,
|
||||
required this.selectedCameraDetails,
|
||||
required this.selectCamera,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final CameraController controller;
|
||||
final double scaleFactor;
|
||||
final Function updateScaleFactor;
|
||||
final SelectedCameraDetails selectedCameraDetails;
|
||||
final void Function(int sCameraId, bool init, bool enableAudio) selectCamera;
|
||||
|
||||
@override
|
||||
State<CameraZoomButtons> createState() => _CameraZoomButtonsState();
|
||||
|
|
@ -31,6 +38,7 @@ String beautifulZoomScale(double scale) {
|
|||
|
||||
class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
||||
bool showWideAngleZoom = false;
|
||||
bool showWideAngleZoomIOS = false;
|
||||
bool _isDisposed = false;
|
||||
|
||||
@override
|
||||
|
|
@ -41,6 +49,9 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
|
||||
Future<void> initAsync() async {
|
||||
showWideAngleZoom = (await widget.controller.getMinZoomLevel()) < 1;
|
||||
if (!showWideAngleZoom && Platform.isIOS && gCameras.length == 3) {
|
||||
showWideAngleZoomIOS = true;
|
||||
}
|
||||
if (_isDisposed) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
|
@ -62,7 +73,11 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
);
|
||||
|
||||
const zoomTextStyle = TextStyle(fontSize: 13);
|
||||
final isMiddleFocused = widget.scaleFactor >= 1 && widget.scaleFactor < 2;
|
||||
final isSmallerFocused = widget.scaleFactor < 1 ||
|
||||
(showWideAngleZoomIOS && widget.selectedCameraDetails.cameraId == 2);
|
||||
final isMiddleFocused = widget.scaleFactor >= 1 &&
|
||||
widget.scaleFactor < 2 &&
|
||||
!(showWideAngleZoomIOS && widget.selectedCameraDetails.cameraId == 2);
|
||||
return Center(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
|
|
@ -71,35 +86,41 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (showWideAngleZoom)
|
||||
if (showWideAngleZoom || showWideAngleZoomIOS)
|
||||
TextButton(
|
||||
style: zoomButtonStyle.copyWith(
|
||||
foregroundColor: WidgetStateProperty.all(
|
||||
(widget.scaleFactor < 1) ? Colors.yellow : Colors.white,
|
||||
isSmallerFocused ? Colors.yellow : Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
final level = await widget.controller.getMinZoomLevel();
|
||||
widget.updateScaleFactor(level);
|
||||
if (showWideAngleZoomIOS) {
|
||||
widget.selectCamera(2, true, false);
|
||||
} else {
|
||||
final level = await widget.controller.getMinZoomLevel();
|
||||
widget.updateScaleFactor(level);
|
||||
}
|
||||
},
|
||||
child: FutureBuilder(
|
||||
future: widget.controller.getMinZoomLevel(),
|
||||
builder: (context, snap) {
|
||||
if (snap.hasData) {
|
||||
final minLevel = beautifulZoomScale(snap.data!);
|
||||
final currentLevel =
|
||||
beautifulZoomScale(widget.scaleFactor);
|
||||
return Text(
|
||||
widget.scaleFactor < 1
|
||||
? '${currentLevel}x'
|
||||
: '${minLevel}x',
|
||||
style: zoomTextStyle,
|
||||
);
|
||||
} else {
|
||||
return const Text('');
|
||||
}
|
||||
},
|
||||
),
|
||||
child: showWideAngleZoomIOS
|
||||
? const Text('0.5')
|
||||
: FutureBuilder(
|
||||
future: widget.controller.getMinZoomLevel(),
|
||||
builder: (context, snap) {
|
||||
if (snap.hasData) {
|
||||
final minLevel = beautifulZoomScale(snap.data!);
|
||||
final currentLevel =
|
||||
beautifulZoomScale(widget.scaleFactor);
|
||||
return Text(
|
||||
widget.scaleFactor < 1
|
||||
? '${currentLevel}x'
|
||||
: '${minLevel}x',
|
||||
style: zoomTextStyle,
|
||||
);
|
||||
} else {
|
||||
return const Text('');
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
style: zoomButtonStyle.copyWith(
|
||||
|
|
@ -108,7 +129,12 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
),
|
||||
),
|
||||
onPressed: () {
|
||||
widget.updateScaleFactor(1.0);
|
||||
if (showWideAngleZoomIOS &&
|
||||
widget.selectedCameraDetails.cameraId == 2) {
|
||||
widget.selectCamera(0, true, false);
|
||||
} else {
|
||||
widget.updateScaleFactor(1.0);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
isMiddleFocused
|
||||
|
|
|
|||
|
|
@ -164,7 +164,6 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// selectCamera(0, init: true);
|
||||
initAsync();
|
||||
}
|
||||
|
||||
|
|
@ -614,6 +613,8 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
scaleFactor:
|
||||
widget.selectedCameraDetails.scaleFactor,
|
||||
updateScaleFactor: updateScaleFactor,
|
||||
selectCamera: widget.selectCamera,
|
||||
selectedCameraDetails: widget.selectedCameraDetails,
|
||||
controller: widget.cameraController!,
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ class _ShareImageView extends State<ShareImageView> {
|
|||
await encryptMediaFiles(
|
||||
widget.mediaUploadId, imageHandler, widget.videoUploadHandler);
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ class _ResponsePreviewState extends State<ResponsePreview> {
|
|||
|
||||
Future<void> initAsync() async {
|
||||
final items = await MemoryItem.convertFromMessages([widget.message]);
|
||||
if (items.length == 1) {
|
||||
if (items.length == 1 && mounted) {
|
||||
setState(() {
|
||||
thumbnailPath = items.values.first.thumbnailPath;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue