mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 15:28:40 +00:00
allow to zoom more than 2x
This commit is contained in:
parent
01a24cc6dc
commit
7e4787f0da
3 changed files with 98 additions and 92 deletions
|
|
@ -34,9 +34,11 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
foregroundColor: Colors.white,
|
||||
minimumSize: Size(40, 40),
|
||||
alignment: Alignment.center,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap);
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
);
|
||||
|
||||
final zoomTextStyle = TextStyle(fontSize: 13);
|
||||
final isMiddleFocused = widget.scaleFactor >= 1 && widget.scaleFactor < 2;
|
||||
return Center(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(40.0),
|
||||
|
|
@ -46,7 +48,11 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TextButton(
|
||||
style: zoomButtonStyle,
|
||||
style: zoomButtonStyle.copyWith(
|
||||
foregroundColor: WidgetStateProperty.all(
|
||||
(widget.scaleFactor < 1) ? Colors.yellow : Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var level = await widget.controller.getMinZoomLevel();
|
||||
widget.updateScaleFactor(level);
|
||||
|
|
@ -55,10 +61,8 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
future: widget.controller.getMinZoomLevel(),
|
||||
builder: (context, snap) {
|
||||
if (snap.hasData) {
|
||||
var minLevel =
|
||||
beautifulZoomScale(snap.data!.toDouble());
|
||||
var currentLevel =
|
||||
beautifulZoomScale(widget.scaleFactor);
|
||||
var minLevel = beautifulZoomScale(snap.data!.toDouble());
|
||||
var currentLevel = beautifulZoomScale(widget.scaleFactor);
|
||||
return Text(
|
||||
widget.scaleFactor < 1
|
||||
? "${currentLevel}x"
|
||||
|
|
@ -68,21 +72,30 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
} else {
|
||||
return Text("");
|
||||
}
|
||||
}),
|
||||
},
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
style: zoomButtonStyle,
|
||||
style: zoomButtonStyle.copyWith(
|
||||
foregroundColor: WidgetStateProperty.all(
|
||||
isMiddleFocused ? Colors.yellow : Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
widget.updateScaleFactor(1.0);
|
||||
},
|
||||
child: Text(
|
||||
(widget.scaleFactor >= 1 && widget.scaleFactor < 2)
|
||||
(isMiddleFocused)
|
||||
? "${beautifulZoomScale(widget.scaleFactor)}x"
|
||||
: "1.0x",
|
||||
style: zoomTextStyle,
|
||||
)),
|
||||
TextButton(
|
||||
style: zoomButtonStyle,
|
||||
style: zoomButtonStyle.copyWith(
|
||||
foregroundColor: WidgetStateProperty.all(
|
||||
(widget.scaleFactor >= 2) ? Colors.yellow : Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var level = min(await widget.controller.getMaxZoomLevel(), 2)
|
||||
.toDouble();
|
||||
|
|
@ -92,8 +105,13 @@ class _CameraZoomButtonsState extends State<CameraZoomButtons> {
|
|||
future: widget.controller.getMaxZoomLevel(),
|
||||
builder: (context, snap) {
|
||||
if (snap.hasData) {
|
||||
var maxLevel = min((snap.data?.toInt())!, 2);
|
||||
return Text("${maxLevel}x", style: zoomTextStyle);
|
||||
var maxLevel = max(
|
||||
min((snap.data?.toInt())!, 2),
|
||||
widget.scaleFactor,
|
||||
);
|
||||
return Text(
|
||||
"${beautifulZoomScale(maxLevel.toDouble())}x",
|
||||
style: zoomTextStyle);
|
||||
} else {
|
||||
return Text("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
bool showSelfieFlash = false;
|
||||
int cameraId = 0;
|
||||
bool isZoomAble = false;
|
||||
double basePanY = 0;
|
||||
double baseScaleFactor = 0;
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
late CameraController controller;
|
||||
|
|
@ -105,6 +107,7 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
}
|
||||
|
||||
Future<void> updateScaleFactor(double newScale) async {
|
||||
if (scaleFactor == newScale) return;
|
||||
var minFactor = await controller.getMinZoomLevel();
|
||||
var maxFactor = await controller.getMaxZoomLevel();
|
||||
if (newScale < minFactor) {
|
||||
|
|
@ -128,6 +131,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
bool get isFront =>
|
||||
controller.description.lensDirection == CameraLensDirection.front;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (cameraId >= gCameras.length) {
|
||||
|
|
@ -158,36 +164,32 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onPanStart: (details) async {
|
||||
// if (cameraState.sensorConfig.sensors.first.position ==
|
||||
// SensorPosition.front) {
|
||||
// return;
|
||||
// }
|
||||
// setState(() {
|
||||
// _basePanY = details.localPosition.dy;
|
||||
// });
|
||||
if (isFront) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
basePanY = details.localPosition.dy;
|
||||
baseScaleFactor = scaleFactor;
|
||||
});
|
||||
},
|
||||
onPanUpdate: (details) async {
|
||||
// if (cameraState.sensorConfig.sensors.first.position ==
|
||||
// SensorPosition.front) {
|
||||
// return;
|
||||
// }
|
||||
// var diff = _basePanY - details.localPosition.dy;
|
||||
// if (diff > 200) diff = 200;
|
||||
// if (diff < 0) diff = 0;
|
||||
// var tmp = (diff / 200 * 50).toInt() / 50;
|
||||
// if (tmp != _lastZoom) {
|
||||
// cameraState.sensorConfig.setZoom(tmp);
|
||||
// setState(() {
|
||||
// (tmp);
|
||||
// _lastZoom = tmp;
|
||||
// });
|
||||
// }
|
||||
if (isFront) {
|
||||
return;
|
||||
}
|
||||
var diff = basePanY - details.localPosition.dy;
|
||||
if (diff > 200) diff = 200;
|
||||
if (diff < -200) diff = -200;
|
||||
var tmp = (diff / 200 * (7 * 2)).toInt() / 2;
|
||||
tmp = baseScaleFactor + tmp;
|
||||
if (tmp < 1) tmp = 1;
|
||||
updateScaleFactor(tmp);
|
||||
},
|
||||
onDoubleTap: () async {
|
||||
selectCamera((cameraId + 1) % 2);
|
||||
|
|
@ -246,10 +248,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
children: [
|
||||
if (controller.value.isInitialized &&
|
||||
isZoomAble &&
|
||||
controller.description.lensDirection !=
|
||||
CameraLensDirection.front)
|
||||
!isFront)
|
||||
SizedBox(
|
||||
width: 150,
|
||||
width: 120,
|
||||
child: CameraZoomButtons(
|
||||
key: widget.key,
|
||||
scaleFactor: scaleFactor,
|
||||
|
|
@ -261,8 +262,7 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
|||
GestureDetector(
|
||||
onTap: () async {
|
||||
if (isFlashOn) {
|
||||
if (controller.description.lensDirection ==
|
||||
CameraLensDirection.front) {
|
||||
if (isFront) {
|
||||
setState(() {
|
||||
showSelfieFlash = true;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,21 +53,13 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
body: ListView(
|
||||
physics: BouncingScrollPhysics(),
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
height: 25,
|
||||
),
|
||||
SizedBox(height: 25),
|
||||
AvatarMakerAvatar(
|
||||
backgroundColor: Colors.transparent,
|
||||
radius: 80,
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Spacer(flex: 2),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
SizedBox(height: 10),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
height: 35,
|
||||
child: ElevatedButton.icon(
|
||||
|
|
@ -82,9 +74,6 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
),
|
||||
),
|
||||
),
|
||||
Spacer(flex: 2),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
const Divider(),
|
||||
BetterListTile(
|
||||
|
|
@ -94,7 +83,6 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
onTap: () async {
|
||||
final displayName =
|
||||
await showDisplayNameChangeDialog(context, user!.displayName);
|
||||
|
||||
if (context.mounted && displayName != null && displayName != "") {
|
||||
updateUserDisplayname(displayName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue