Files
SDKmuta/lib/widgets/camera_sheet.dart
T
Jan Pleterski d4bc01f202 stage2
2026-11-13 09:15:17 +01:00

237 lines
6.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
/// Bottom sheet used by every menu on the camera stream: the live image stays
/// visible and undimmed above it, so changes can be judged immediately.
Future<T?> showCameraSheet<T>(BuildContext context,
{required WidgetBuilder builder}) {
return showModalBottomSheet<T>(
context: context,
barrierColor: Colors.transparent,
backgroundColor: Colors.grey[900],
isScrollControlled:
true, // tall content (timer) may use more than half the screen
builder: (sheet) => SafeArea(
child: ConstrainedBox(
constraints:
BoxConstraints(maxHeight: MediaQuery.sizeOf(sheet).height * 0.75),
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 16),
child: builder(sheet),
),
),
),
);
}
/// Title (+ optional subtitle) on the left, optional action on the right.
class CameraSheetHeader extends StatelessWidget {
final String title;
final String? subtitle;
final IconData? icon;
final Color? iconColor;
final Widget? trailing;
const CameraSheetHeader({
super.key,
required this.title,
this.subtitle,
this.icon,
this.iconColor,
this.trailing,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 14),
child: Row(
children: [
if (icon != null) ...[
Icon(icon, color: iconColor ?? Colors.white, size: 22),
const SizedBox(width: 8),
],
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold)),
if (subtitle != null)
Text(subtitle!,
style:
const TextStyle(color: Colors.white54, fontSize: 12)),
],
),
),
if (trailing != null) trailing!,
],
),
);
}
}
/// Icon, label, slider and current value in one row.
class SheetSlider extends StatelessWidget {
final IconData icon;
final String label;
final String valueText;
final double value;
final double min;
final double max;
final Color accent;
final ValueChanged<double> onChanged;
const SheetSlider({super.key,
required this.icon,
required this.label,
required this.valueText,
required this.value,
required this.min,
required this.max,
required this.accent,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, color: Colors.white54, size: 20),
const SizedBox(width: 8),
SizedBox(
width: 72,
child: Text(label,
style: const TextStyle(color: Colors.white, fontSize: 13)),
),
Expanded(
child: Slider(
value: value.clamp(min, max),
min: min,
max: max,
activeColor: accent,
inactiveColor: Colors.white24,
onChanged: onChanged,
),
),
SizedBox(
width: 46,
child: Text(
valueText,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white70,
fontSize: 13,
fontFeatures: [FontFeature.tabularFigures()]),
),
),
],
);
}
}
/// Wide button that shows an on/off state with the accent color.
class SheetToggle extends StatelessWidget {
final IconData icon;
final String label;
final bool active;
final Color accent;
final VoidCallback onTap;
const SheetToggle({super.key,
required this.icon,
required this.label,
required this.active,
required this.accent,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Material(
color: active
? accent.withValues(alpha: 0.18)
: Colors.white.withValues(alpha: 0.06),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side:
BorderSide(color: active ? accent : Colors.transparent, width: 1.5),
),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 18, color: active ? accent : Colors.white70),
const SizedBox(width: 6),
Flexible(
child: Text(
label,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
color: active ? Colors.white : Colors.white70),
),
),
],
),
),
),
);
}
}
/// Big number with − / + buttons, used for the bullet count.
class SheetStepper extends StatelessWidget {
final int value;
final int min;
final int max;
final Color accent;
final ValueChanged<int> onChanged;
const SheetStepper({
super.key,
required this.value,
required this.min,
required this.max,
required this.accent,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
Widget button(IconData icon, bool enabled, int next) => IconButton(
onPressed: enabled ? () => onChanged(next) : null,
icon: Icon(icon, color: Colors.white, size: 28),
style: IconButton.styleFrom(
backgroundColor:
Colors.white.withValues(alpha: enabled ? 0.12 : 0.04),
shape: const CircleBorder(),
minimumSize: const Size(56, 56),
),
);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
button(Icons.remove, value > min, value - 1),
SizedBox(
width: 120,
child: Text(
'$value',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 56, fontWeight: FontWeight.bold, color: accent),
),
),
button(Icons.add, value < max, value + 1),
],
);
}
}