Files
Redesnigned-Finamp/lib/components/LayoutSettingsScreen/theme_selector.dart
T
Zakaria d0ca84d8d2
Build / Build for Android (push) Has been cancelled
Build / Build for iOS (push) Has been cancelled
redesign app phase 1
2026-05-18 14:34:41 -04:00

53 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:finamp/l10n/app_localizations.dart';
import 'package:hive/hive.dart';
import '../../services/theme_mode_helper.dart';
extension LocalisedName on ThemeMode {
String toLocalisedString(BuildContext context) =>
_humanReadableLocalisedName(this, context);
String _humanReadableLocalisedName(
ThemeMode themeMode, BuildContext context) {
switch (themeMode) {
case ThemeMode.system:
return AppLocalizations.of(context)!.system;
case ThemeMode.light:
return AppLocalizations.of(context)!.light;
case ThemeMode.dark:
return AppLocalizations.of(context)!.dark;
}
}
}
class ThemeSelector extends StatelessWidget {
const ThemeSelector({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Box<ThemeMode>>(
valueListenable: ThemeModeHelper.themeModeListener,
builder: (_, box, __) {
return ListTile(
title: const Text("Theme"),
trailing: DropdownButton<ThemeMode>(
value: box.get("ThemeMode"),
items: ThemeMode.values
.map((e) => DropdownMenuItem<ThemeMode>(
value: e,
child: Text(e.toLocalisedString(context)),
))
.toList(),
onChanged: (value) {
if (value != null) {
ThemeModeHelper.setThemeMode(value);
}
},
),
);
},
);
}
}