feature: Rework responsive layout (#217)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-02-07 15:55:01 +01:00 committed by GitHub
parent e07f280124
commit 8012fdcea8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 1468 additions and 1040 deletions

View file

@ -10,6 +10,8 @@ part 'home_settings_model.g.dart';
@freezed
class HomeSettingsModel with _$HomeSettingsModel {
factory HomeSettingsModel({
@Default({...LayoutMode.values}) Set<LayoutMode> screenLayouts,
@Default({...ViewSize.values}) Set<ViewSize> layoutStates,
@Default(HomeBanner.carousel) HomeBanner homeBanner,
@Default(HomeCarouselSettings.combined) HomeCarouselSettings carouselSettings,
@Default(HomeNextUp.separate) HomeNextUp nextUp,
@ -18,6 +20,48 @@ class HomeSettingsModel with _$HomeSettingsModel {
factory HomeSettingsModel.fromJson(Map<String, dynamic> json) => _$HomeSettingsModelFromJson(json);
}
T selectAvailableOrSmaller<T>(T value, Set<T> availableOptions, List<T> allOptions) {
if (availableOptions.contains(value)) {
return value;
}
int index = allOptions.indexOf(value);
for (int i = index - 1; i >= 0; i--) {
if (availableOptions.contains(allOptions[i])) {
return allOptions[i];
}
}
return availableOptions.first;
}
enum ViewSize {
phone,
tablet,
desktop;
const ViewSize();
String label(BuildContext context) => switch (this) {
ViewSize.phone => context.localized.phone,
ViewSize.tablet => context.localized.tablet,
ViewSize.desktop => context.localized.desktop,
};
}
enum LayoutMode {
single,
dual;
const LayoutMode();
String label(BuildContext context) => switch (this) {
LayoutMode.single => context.localized.layoutModeSingle,
LayoutMode.dual => context.localized.layoutModeDual,
};
}
enum HomeBanner {
hide,
carousel,