2024-11-06 13:23:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
|
|
|
import 'package:lightmeter/navigation/routes.dart';
|
|
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
|
|
|
import 'package:lightmeter/screens/equipment_profile_edit/flow_equipment_profile_edit.dart';
|
|
|
|
import 'package:lightmeter/screens/shared/sliver_placeholder/widget_sliver_placeholder.dart';
|
|
|
|
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
|
|
|
|
class EquipmentProfilesScreen extends StatefulWidget {
|
|
|
|
const EquipmentProfilesScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<EquipmentProfilesScreen> createState() => _EquipmentProfilesScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> with SingleTickerProviderStateMixin {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SliverScreen(
|
2024-11-06 18:11:49 +00:00
|
|
|
title: Text(S.of(context).equipmentProfiles),
|
2024-11-06 13:23:46 +00:00
|
|
|
appBarActions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: _addProfile,
|
|
|
|
icon: const Icon(Icons.add_outlined),
|
|
|
|
tooltip: S.of(context).tooltipAdd,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
slivers: [
|
2024-11-06 18:11:49 +00:00
|
|
|
if (EquipmentProfiles.of(context).length > 1)
|
2024-11-06 13:23:46 +00:00
|
|
|
_EquipmentProfilesListBuilder(
|
2024-11-06 18:11:49 +00:00
|
|
|
values: EquipmentProfiles.of(context).skip(1).toList(),
|
2024-11-06 13:23:46 +00:00
|
|
|
onEdit: _editProfile,
|
2024-11-11 12:18:13 +00:00
|
|
|
onCheckbox: EquipmentProfilesProvider.of(context).toggleProfile,
|
2024-11-06 13:23:46 +00:00
|
|
|
)
|
|
|
|
else
|
|
|
|
SliverPlaceholder(onTap: _addProfile),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addProfile() {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
NavigationRoutes.equipmentProfileEditScreen.name,
|
2024-11-08 09:37:44 +00:00
|
|
|
arguments: const EquipmentProfileEditArgs(editType: EquipmentProfileEditType.add),
|
2024-11-06 13:23:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _editProfile(EquipmentProfile profile) {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
NavigationRoutes.equipmentProfileEditScreen.name,
|
2024-11-08 09:37:44 +00:00
|
|
|
arguments: EquipmentProfileEditArgs(
|
|
|
|
editType: EquipmentProfileEditType.edit,
|
|
|
|
profile: profile,
|
|
|
|
),
|
2024-11-06 13:23:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EquipmentProfilesListBuilder extends StatelessWidget {
|
|
|
|
final List<EquipmentProfile> values;
|
|
|
|
final void Function(EquipmentProfile film) onEdit;
|
2024-11-11 12:18:13 +00:00
|
|
|
final void Function(EquipmentProfile film, bool value) onCheckbox;
|
2024-11-06 13:23:46 +00:00
|
|
|
|
|
|
|
const _EquipmentProfilesListBuilder({
|
|
|
|
required this.values,
|
|
|
|
required this.onEdit,
|
2024-11-11 12:18:13 +00:00
|
|
|
required this.onCheckbox,
|
2024-11-06 13:23:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SliverList.builder(
|
|
|
|
itemCount: values.length,
|
|
|
|
itemBuilder: (_, index) => Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
Dimens.paddingM,
|
|
|
|
index == 0 ? Dimens.paddingM : 0,
|
|
|
|
Dimens.paddingM,
|
|
|
|
index == values.length - 1 ? Dimens.paddingM + MediaQuery.paddingOf(context).bottom : 0.0,
|
|
|
|
),
|
|
|
|
child: Card(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
top: index == 0 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero,
|
|
|
|
bottom: index == values.length - 1 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: index == 0 ? Dimens.paddingM : 0.0,
|
|
|
|
bottom: index == values.length - 1 ? Dimens.paddingM : 0.0,
|
|
|
|
),
|
2024-11-11 12:00:09 +00:00
|
|
|
child: CheckboxListTile(
|
2024-11-06 13:23:46 +00:00
|
|
|
title: Text(values[index].name),
|
2024-11-11 12:00:09 +00:00
|
|
|
controlAffinity: ListTileControlAffinity.leading,
|
2024-11-11 12:18:13 +00:00
|
|
|
value: EquipmentProfiles.inUseOf(context).contains(values[index]),
|
|
|
|
onChanged: (value) => onCheckbox(values[index], value ?? false),
|
2024-11-11 12:00:09 +00:00
|
|
|
secondary: IconButton(
|
2024-11-06 13:23:46 +00:00
|
|
|
onPressed: () => onEdit(values[index]),
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|