mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-18 23:35:25 +02:00
added zoom selector
This commit is contained in:
parent
fc19c81127
commit
50191a305e
@ -1,3 +1,7 @@
|
||||
import 'dart:collection';
|
||||
|
||||
const DURATION_INFINITY = Duration(days: 999);
|
||||
const SECONDARY_BUTTONS_DURATION_MULTIPLIER = 1.8;
|
||||
const PHOTO_SHOW_AFTER_CREATION_DURATION = Duration(milliseconds: 500);
|
||||
final UnmodifiableSetView<double> DEFAULT_ZOOM_LEVELS =
|
||||
UnmodifiableSetView({0.6, 1, 2, 5, 10, 20, 50, 100});
|
||||
|
@ -29,6 +29,9 @@ class MainScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
final List<double> zoomLevels = [1.0];
|
||||
int currentZoomLevelIndex = 0;
|
||||
|
||||
bool isRecording = false;
|
||||
bool lockCamera = false;
|
||||
bool isTorchEnabled = false;
|
||||
@ -39,6 +42,17 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
|
||||
CameraController? controller;
|
||||
|
||||
static String formatZoomLevel(double zoomLevel) {
|
||||
if (zoomLevel.floor() == zoomLevel) {
|
||||
// Zoom level is a whole number
|
||||
return '${zoomLevel.floor()}x';
|
||||
} else {
|
||||
return '${zoomLevel.toStringAsFixed(1)}x';
|
||||
}
|
||||
}
|
||||
|
||||
double get currentZoomLevel => zoomLevels[currentZoomLevelIndex];
|
||||
|
||||
@override
|
||||
bool get isLoading =>
|
||||
super.isLoading || controller == null || !controller!.value.isInitialized;
|
||||
@ -113,12 +127,34 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
|
||||
controller!.initialize().then((_) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
await controller!.initialize();
|
||||
|
||||
setState(() {});
|
||||
await determineZoomLevels();
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future<void> determineZoomLevels() async {
|
||||
final minZoomLevel = await controller!.getMinZoomLevel();
|
||||
final maxZoomLevel = await controller!.getMaxZoomLevel();
|
||||
|
||||
final availableZoomLevels = List<double>.from(
|
||||
DEFAULT_ZOOM_LEVELS
|
||||
.where((zoomLevel) =>
|
||||
zoomLevel >= minZoomLevel && zoomLevel <= maxZoomLevel)
|
||||
.toSet(),
|
||||
)
|
||||
..add(minZoomLevel)
|
||||
..add(maxZoomLevel)
|
||||
..toList()
|
||||
..sort();
|
||||
|
||||
setState(() {
|
||||
zoomLevels.addAll(availableZoomLevels);
|
||||
});
|
||||
}
|
||||
|
||||
@ -328,6 +364,7 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
expandableContent: Padding(
|
||||
padding: const EdgeInsets.all(LARGE_SPACE),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.flashlight_on_rounded),
|
||||
@ -352,6 +389,31 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
});
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(_) => Colors.white10,
|
||||
),
|
||||
foregroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(_) => Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
final newZoomLevelIndex =
|
||||
((currentZoomLevel + 1) % zoomLevels.length).toInt();
|
||||
print(newZoomLevelIndex);
|
||||
print(zoomLevels);
|
||||
|
||||
controller!.setZoomLevel(zoomLevels[newZoomLevelIndex]);
|
||||
|
||||
setState(() {
|
||||
currentZoomLevelIndex = newZoomLevelIndex;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
formatZoomLevel(currentZoomLevel),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user