Files
COPILOT/copilot_keyboard/lib/presentation/widgets/preset_buttons.dart
klas 40143734fc Initial commit: COPILOT D6 Flutter keyboard controller
Flutter web app replacing legacy WPF CCTV surveillance keyboard controller.
Includes wall overview, section view with monitor grid, camera input,
PTZ control, alarm/lock/sequence BLoCs, and legacy-matching UI styling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 14:57:38 +01:00

94 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../blocs/ptz/ptz_bloc.dart';
import '../blocs/ptz/ptz_event.dart';
import '../blocs/monitor/monitor_bloc.dart';
import '../blocs/monitor/monitor_state.dart';
class PresetButtons extends StatelessWidget {
final int presetCount;
const PresetButtons({super.key, this.presetCount = 8});
@override
Widget build(BuildContext context) {
return BlocBuilder<MonitorBloc, MonitorBlocState>(
builder: (context, monitorState) {
final cameraId = monitorState.selectedMonitorCamera;
final isEnabled = cameraId != null && cameraId > 0;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'PRESETS',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
Wrap(
spacing: 4,
runSpacing: 4,
children: List.generate(presetCount, (index) {
final presetId = index + 1;
return _PresetButton(
presetId: presetId,
isEnabled: isEnabled,
onPressed: isEnabled
? () => context.read<PtzBloc>().add(
PtzGoToPreset(cameraId: cameraId, preset: presetId),
)
: null,
);
}),
),
],
);
},
);
}
}
class _PresetButton extends StatelessWidget {
final int presetId;
final bool isEnabled;
final VoidCallback? onPressed;
const _PresetButton({
required this.presetId,
required this.isEnabled,
this.onPressed,
});
@override
Widget build(BuildContext context) {
return SizedBox(
width: 44,
height: 36,
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: isEnabled
? Theme.of(context).colorScheme.secondaryContainer
: Theme.of(context).colorScheme.surfaceContainerHighest,
foregroundColor: isEnabled
? Theme.of(context).colorScheme.onSecondaryContainer
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.4),
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
child: Text(
'$presetId',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
),
);
}
}