mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat: use system color scheme
This commit is contained in:
parent
bb60b01ef2
commit
862c4b8faf
@ -3,8 +3,10 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
import 'package:spotube/provider/user_preferences_provider.dart';
|
import 'package:spotube/provider/user_preferences_provider.dart';
|
||||||
|
import 'package:system_theme/system_theme.dart';
|
||||||
|
|
||||||
final colorsMap = {
|
final Map<String, Color> colorsMap = {
|
||||||
|
"System": SystemTheme.accentColor.accent,
|
||||||
"Red": Colors.red,
|
"Red": Colors.red,
|
||||||
"Pink": Colors.pink,
|
"Pink": Colors.pink,
|
||||||
"Purple": Colors.purple,
|
"Purple": Colors.purple,
|
||||||
@ -23,15 +25,8 @@ final colorsMap = {
|
|||||||
"Brown": Colors.brown,
|
"Brown": Colors.brown,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ColorSchemeType {
|
|
||||||
accent,
|
|
||||||
background,
|
|
||||||
}
|
|
||||||
|
|
||||||
class ColorSchemePickerDialog extends HookConsumerWidget {
|
class ColorSchemePickerDialog extends HookConsumerWidget {
|
||||||
final ColorSchemeType schemeType;
|
const ColorSchemePickerDialog({Key? key}) : super(key: key);
|
||||||
const ColorSchemePickerDialog({required this.schemeType, Key? key})
|
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
@ -44,20 +39,12 @@ class ColorSchemePickerDialog extends HookConsumerWidget {
|
|||||||
).key);
|
).key);
|
||||||
|
|
||||||
onOk() {
|
onOk() {
|
||||||
switch (schemeType) {
|
preferences.setAccentColorScheme(colorsMap[active.value]!);
|
||||||
case ColorSchemeType.accent:
|
|
||||||
preferences.setAccentColorScheme(colorsMap[active.value]!);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
preferences.setBackgroundColorScheme(
|
|
||||||
colorsMap[active.value]!,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("Pick ${schemeType.name} color scheme"),
|
title: const Text("Pick color scheme"),
|
||||||
actions: [
|
actions: [
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
child: const Text("Cancel"),
|
child: const Text("Cancel"),
|
||||||
@ -96,7 +83,7 @@ class ColorSchemePickerDialog extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ColorTile extends StatelessWidget {
|
class ColorTile extends StatelessWidget {
|
||||||
final MaterialColor color;
|
final Color color;
|
||||||
final bool isActive;
|
final bool isActive;
|
||||||
final void Function()? onPressed;
|
final void Function()? onPressed;
|
||||||
final String? tooltip;
|
final String? tooltip;
|
||||||
@ -111,7 +98,7 @@ class ColorTile extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
factory ColorTile.compact({
|
factory ColorTile.compact({
|
||||||
required MaterialColor color,
|
required Color color,
|
||||||
bool isActive = false,
|
bool isActive = false,
|
||||||
void Function()? onPressed,
|
void Function()? onPressed,
|
||||||
String? tooltip = "",
|
String? tooltip = "",
|
||||||
@ -138,7 +125,11 @@ class ColorTile extends StatelessWidget {
|
|||||||
border: isActive
|
border: isActive
|
||||||
? Border.fromBorderSide(
|
? Border.fromBorderSide(
|
||||||
BorderSide(
|
BorderSide(
|
||||||
color: color[100]!,
|
color: Color.lerp(
|
||||||
|
theme.colorScheme.primary,
|
||||||
|
theme.colorScheme.onPrimary,
|
||||||
|
0.5,
|
||||||
|
)!,
|
||||||
width: 4,
|
width: 4,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -149,16 +140,13 @@ class ColorTile extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isCompact) {
|
if (isCompact) {
|
||||||
return Tooltip(
|
return GestureDetector(
|
||||||
message: tooltip,
|
onTap: onPressed,
|
||||||
child: GestureDetector(
|
child: lead,
|
||||||
onTap: onPressed,
|
|
||||||
child: lead,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final colorScheme = ColorScheme.fromSwatch(primarySwatch: color);
|
final colorScheme = ColorScheme.fromSeed(seedColor: color);
|
||||||
|
|
||||||
final palette = [
|
final palette = [
|
||||||
colorScheme.primary,
|
colorScheme.primary,
|
||||||
@ -173,46 +161,43 @@ class ColorTile extends StatelessWidget {
|
|||||||
colorScheme.onSurface,
|
colorScheme.onSurface,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Tooltip(
|
return GestureDetector(
|
||||||
message: tooltip,
|
onTap: onPressed,
|
||||||
child: GestureDetector(
|
child: Column(
|
||||||
onTap: onPressed,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
child: Column(
|
children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
lead,
|
||||||
children: [
|
const SizedBox(width: 10),
|
||||||
lead,
|
Text(
|
||||||
const SizedBox(width: 10),
|
tooltip!,
|
||||||
Text(
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
tooltip!,
|
color: theme.colorScheme.primary,
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
fontWeight: FontWeight.w600,
|
||||||
color: theme.colorScheme.primary,
|
),
|
||||||
fontWeight: FontWeight.w600,
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Wrap(
|
||||||
|
alignment: WrapAlignment.start,
|
||||||
|
spacing: 10,
|
||||||
|
runSpacing: 10,
|
||||||
|
children: [
|
||||||
|
...palette.map(
|
||||||
|
(e) => Container(
|
||||||
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: e,
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(height: 10),
|
),
|
||||||
Wrap(
|
],
|
||||||
alignment: WrapAlignment.start,
|
|
||||||
spacing: 10,
|
|
||||||
runSpacing: 10,
|
|
||||||
children: [
|
|
||||||
...palette.map(
|
|
||||||
(e) => Container(
|
|
||||||
height: 20,
|
|
||||||
width: 20,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: e,
|
|
||||||
borderRadius: BorderRadius.circular(5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import 'package:spotube/themes/theme.dart';
|
|||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:window_size/window_size.dart';
|
import 'package:window_size/window_size.dart';
|
||||||
|
import 'package:system_theme/system_theme.dart';
|
||||||
|
|
||||||
void main(List<String> rawArgs) async {
|
void main(List<String> rawArgs) async {
|
||||||
final parser = ArgParser();
|
final parser = ArgParser();
|
||||||
@ -67,6 +68,7 @@ void main(List<String> rawArgs) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await SystemTheme.accentColor.load();
|
||||||
await QueryClient.initialize(cachePrefix: "oss.krtirtho.spotube");
|
await QueryClient.initialize(cachePrefix: "oss.krtirtho.spotube");
|
||||||
Hive.registerAdapter(CacheTrackAdapter());
|
Hive.registerAdapter(CacheTrackAdapter());
|
||||||
Hive.registerAdapter(CacheTrackEngagementAdapter());
|
Hive.registerAdapter(CacheTrackEngagementAdapter());
|
||||||
|
@ -23,13 +23,11 @@ class SettingsPage extends HookConsumerWidget {
|
|||||||
final auth = ref.watch(AuthenticationNotifier.provider);
|
final auth = ref.watch(AuthenticationNotifier.provider);
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
final pickColorScheme = useCallback((ColorSchemeType schemeType) {
|
final pickColorScheme = useCallback(() {
|
||||||
return () => showDialog(
|
return () => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return ColorSchemePickerDialog(
|
return const ColorSchemePickerDialog();
|
||||||
schemeType: schemeType,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -195,10 +193,10 @@ class SettingsPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
trailing: ColorTile.compact(
|
trailing: ColorTile.compact(
|
||||||
color: preferences.accentColorScheme,
|
color: preferences.accentColorScheme,
|
||||||
onPressed: pickColorScheme(ColorSchemeType.accent),
|
onPressed: pickColorScheme(),
|
||||||
isActive: true,
|
isActive: true,
|
||||||
),
|
),
|
||||||
onTap: pickColorScheme(ColorSchemeType.accent),
|
onTap: pickColorScheme(),
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
secondary: const Icon(SpotubeIcons.album),
|
secondary: const Icon(SpotubeIcons.album),
|
||||||
|
@ -30,7 +30,7 @@ class UserPreferences extends PersistedChangeNotifier {
|
|||||||
bool checkUpdate;
|
bool checkUpdate;
|
||||||
AudioQuality audioQuality;
|
AudioQuality audioQuality;
|
||||||
|
|
||||||
MaterialColor accentColorScheme;
|
Color accentColorScheme;
|
||||||
bool skipSponsorSegments;
|
bool skipSponsorSegments;
|
||||||
|
|
||||||
String downloadLocation;
|
String downloadLocation;
|
||||||
@ -93,7 +93,7 @@ class UserPreferences extends PersistedChangeNotifier {
|
|||||||
updatePersistence();
|
updatePersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccentColorScheme(MaterialColor color) {
|
void setAccentColorScheme(Color color) {
|
||||||
accentColorScheme = color;
|
accentColorScheme = color;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
updatePersistence();
|
updatePersistence();
|
||||||
|
@ -28,7 +28,6 @@ dependencies:
|
|||||||
file_picker: ^5.2.2
|
file_picker: ^5.2.2
|
||||||
fl_query: ^1.0.0-alpha.2
|
fl_query: ^1.0.0-alpha.2
|
||||||
fl_query_hooks: ^1.0.0-alpha.2
|
fl_query_hooks: ^1.0.0-alpha.2
|
||||||
fluent_ui: ^4.3.0
|
|
||||||
fluentui_system_icons: ^1.1.189
|
fluentui_system_icons: ^1.1.189
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user