nc-photos/app/lib/widget/zoom_menu_button.dart

88 lines
1.9 KiB
Dart
Raw Normal View History

2021-07-25 10:52:24 +02:00
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/theme.dart';
2021-07-25 10:52:24 +02:00
class ZoomMenuButton extends StatelessWidget {
2021-09-15 08:58:06 +02:00
const ZoomMenuButton({
2021-07-25 10:52:24 +02:00
Key? key,
required this.initialZoom,
required this.minZoom,
required this.maxZoom,
this.onZoomChanged,
}) : super(key: key);
@override
build(BuildContext context) {
return PopupMenuButton(
icon: const Icon(Icons.photo_size_select_large),
tooltip: L10n.global().zoomTooltip,
2021-07-25 10:52:24 +02:00
itemBuilder: (context) => [
_PopupMenuZoom(
initialValue: initialZoom,
minValue: minZoom,
maxValue: maxZoom,
onChanged: onZoomChanged,
),
],
);
}
final int initialZoom;
final int minZoom;
final int maxZoom;
final ValueChanged<int>? onZoomChanged;
}
class _PopupMenuZoom extends PopupMenuEntry<void> {
2021-09-15 08:58:06 +02:00
const _PopupMenuZoom({
2021-07-25 10:52:24 +02:00
Key? key,
required this.initialValue,
required this.minValue,
required this.maxValue,
this.onChanged,
}) : super(key: key);
@override
represents(void value) => false;
@override
createState() => _PopupMenuZoomState();
@override
// this value doesn't seems to do anything?
final double height = 48.0;
final int initialValue;
final int minValue;
final int maxValue;
final ValueChanged<int>? onChanged;
}
class _PopupMenuZoomState extends State<_PopupMenuZoom> {
@override
initState() {
super.initState();
_value = widget.initialValue;
}
@override
build(BuildContext context) {
return AppTheme(
child: Slider(
value: _value.toDouble(),
min: widget.minValue.toDouble(),
max: widget.maxValue.toDouble(),
divisions: (widget.maxValue - widget.minValue).round(),
onChanged: (value) {
setState(() {
_value = value.round();
});
widget.onChanged?.call(_value);
},
),
2021-07-25 10:52:24 +02:00
);
}
late int _value;
}