simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -12,6 +12,7 @@ import '../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../storage/timetable_favorites_settings.dart';
|
||||
import '../../../utils/haptics.dart';
|
||||
import '../../../widget/app_progress_indicator.dart';
|
||||
import 'element_type_icon.dart';
|
||||
|
||||
/// Full-screen picker: choose an element type (or "Alle" to search across all
|
||||
/// types), filter the (potentially large) list client-side, and pick an element
|
||||
@@ -221,7 +222,7 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: ChoiceChip(
|
||||
avatar: Icon(type == null ? Icons.apps : _iconFor(type), size: 18),
|
||||
avatar: Icon(type == null ? Icons.apps : type.icon, size: 18),
|
||||
showCheckmark: false,
|
||||
label: Text(type?.label ?? 'Alle'),
|
||||
selected: _selectedType == type,
|
||||
@@ -293,7 +294,7 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
}
|
||||
}
|
||||
final item = filtered[index - headerCount];
|
||||
return _itemTile(item);
|
||||
return _itemTile(item, favorites);
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -316,7 +317,7 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
|
||||
Widget _favoriteTile(FavoriteTimetableElement favorite) {
|
||||
return ListTile(
|
||||
leading: Icon(_iconFor(favorite.type)),
|
||||
leading: Icon(favorite.type.icon),
|
||||
title: Text(favorite.label),
|
||||
subtitle: Text(favorite.type.label),
|
||||
trailing: IconButton(
|
||||
@@ -329,12 +330,10 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _itemTile(_PickerItem item) {
|
||||
final isFavorite = context
|
||||
.watch<SettingsCubit>()
|
||||
.val()
|
||||
.timetableFavoritesSettings
|
||||
.isFavorite(item.type, item.id);
|
||||
Widget _itemTile(_PickerItem item, List<FavoriteTimetableElement> favorites) {
|
||||
final isFavorite = favorites.any(
|
||||
(f) => f.type == item.type && f.id == item.id,
|
||||
);
|
||||
|
||||
// In the "Alle" tab the type is otherwise ambiguous, so surface it.
|
||||
final subtitleParts = <String>[
|
||||
@@ -344,7 +343,7 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
];
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(_iconFor(item.type)),
|
||||
leading: Icon(item.type.icon),
|
||||
title: Text(item.primary),
|
||||
subtitle: subtitleParts.isEmpty ? null : Text(subtitleParts.join(' · ')),
|
||||
trailing: IconButton(
|
||||
@@ -355,19 +354,6 @@ class _ElementPickerPageState extends State<ElementPickerPage> {
|
||||
onTap: () => _open(item),
|
||||
);
|
||||
}
|
||||
|
||||
static IconData _iconFor(TimetableElementType type) {
|
||||
switch (type) {
|
||||
case TimetableElementType.student:
|
||||
return Icons.person_outline;
|
||||
case TimetableElementType.teacher:
|
||||
return Icons.school_outlined;
|
||||
case TimetableElementType.room:
|
||||
return Icons.meeting_room_outlined;
|
||||
case TimetableElementType.schoolClass:
|
||||
return Icons.groups_outlined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _PickerItem {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../api/marianumconnect/queries/timetable_get_element_week/timetable_element_type.dart';
|
||||
|
||||
extension TimetableElementTypeIcon on TimetableElementType {
|
||||
IconData get icon => switch (this) {
|
||||
TimetableElementType.student => Icons.person_outline,
|
||||
TimetableElementType.teacher => Icons.school_outlined,
|
||||
TimetableElementType.room => Icons.meeting_room_outlined,
|
||||
TimetableElementType.schoolClass => Icons.groups_outlined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user