mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-10-21 23:11:45 +02:00
The Material theme now draws its main surfaces with rounded Material Symbols: navigation, player, mini player, queue, settings, sheets, dialogs and shared controls. AppIcon maps legacy Icons to their symbol and keeps outlined glyphs unfilled. Mornye keeps its original icons. Icon buttons, text and filled buttons, dialog actions, sliders, the setup FAB and indeterminate spinners use the Material 3 Expressive components. Each wrapper falls back to the standard Flutter widget for Mornye, reduced motion and custom sizing, so existing layouts and hit areas stay intact.
73 lines
2.5 KiB
Dart
73 lines
2.5 KiB
Dart
import 'package:file_picker/file_picker.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:spotiflac_android/l10n/l10n.dart';
|
|
import 'package:spotiflac_android/providers/theme_provider.dart';
|
|
import 'package:spotiflac_android/services/custom_font_service.dart';
|
|
import 'package:spotiflac_android/theme/mornye_theme.dart';
|
|
import 'package:spotiflac_android/widgets/app_icon_button.dart';
|
|
import 'package:spotiflac_android/widgets/app_loading_indicator.dart';
|
|
|
|
class CustomFontSetting extends ConsumerStatefulWidget {
|
|
const CustomFontSetting({super.key});
|
|
|
|
@override
|
|
ConsumerState<CustomFontSetting> createState() => _CustomFontSettingState();
|
|
}
|
|
|
|
class _CustomFontSettingState extends ConsumerState<CustomFontSetting> {
|
|
bool _importing = false;
|
|
|
|
Future<void> _import() async {
|
|
setState(() => _importing = true);
|
|
try {
|
|
final file = await FilePicker.pickFile(
|
|
type: FileType.custom,
|
|
allowedExtensions: ['ttf', 'otf'],
|
|
);
|
|
if (file == null || !mounted) return;
|
|
if ((await file.length() ?? 0) > CustomFontService.maxBytes) {
|
|
throw const FormatException('Font exceeds import limit');
|
|
}
|
|
final id = await CustomFontService.instance.import(
|
|
await file.readAsBytes(),
|
|
);
|
|
if (!mounted) return;
|
|
await ref.read(themeProvider.notifier).setCustomFont(id, file.name);
|
|
} catch (_) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(context.l10n.appearanceCustomFontInvalid)),
|
|
);
|
|
}
|
|
} finally {
|
|
if (mounted) setState(() => _importing = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = ref.watch(themeProvider);
|
|
return ListTile(
|
|
leading: context.isMornye ? null : const Icon(Icons.text_fields),
|
|
title: Text(context.l10n.appearanceCustomFont),
|
|
subtitle: Text(
|
|
theme.customFontId.isEmpty
|
|
? context.l10n.appearanceCustomFontSubtitle
|
|
: theme.customFontName,
|
|
),
|
|
onTap: _importing ? null : _import,
|
|
trailing: _importing
|
|
? const AppLoadingIndicator(size: 24, strokeWidth: 2)
|
|
: theme.customFontId.isEmpty
|
|
? const Icon(Icons.add)
|
|
: AppIconButton(
|
|
tooltip: context.l10n.appearanceCustomFontReset,
|
|
onPressed: () =>
|
|
ref.read(themeProvider.notifier).setCustomFont('', ''),
|
|
icon: const Icon(Icons.close),
|
|
),
|
|
);
|
|
}
|
|
}
|