2026-08-05 10:57:40 +08:00
|
|
|
import 'package:fl_clash/common/constant.dart';
|
2026-09-05 20:09:39 +08:00
|
|
|
import 'package:fl_clash/providers/providers.dart';
|
2026-10-16 14:55:07 +08:00
|
|
|
import 'package:fl_clash/ui/color.dart';
|
2026-09-05 20:09:39 +08:00
|
|
|
import 'package:material_ui/material_ui.dart';
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2026-08-05 10:57:40 +08:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2026-09-25 03:57:04 +08:00
|
|
|
import 'package:material_color_utilities/hct/hct.dart';
|
2026-08-05 10:57:40 +08:00
|
|
|
|
|
|
|
|
void main() {
|
2026-09-05 20:09:39 +08:00
|
|
|
test(
|
|
|
|
|
'DynamicColor falls back to the default primary color before seeding',
|
|
|
|
|
() {
|
|
|
|
|
final container = ProviderContainer();
|
|
|
|
|
addTearDown(container.dispose);
|
|
|
|
|
expect(
|
|
|
|
|
container.read(dynamicColorProvider).accentColor,
|
|
|
|
|
const Color(defaultPrimaryColor),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
test('genColorScheme seeds each brightness from its own dynamic seed', () {
|
|
|
|
|
const lightSeed = Color(0xFF00FF00);
|
|
|
|
|
const darkSeed = Color(0xFF0000FF);
|
|
|
|
|
final container = ProviderContainer();
|
|
|
|
|
addTearDown(container.dispose);
|
|
|
|
|
container
|
|
|
|
|
.read(dynamicColorProvider.notifier)
|
|
|
|
|
.seed(
|
|
|
|
|
lightSeed: lightSeed,
|
|
|
|
|
darkSeed: darkSeed,
|
|
|
|
|
accentColor: const Color(defaultPrimaryColor),
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-16 22:42:17 +08:00
|
|
|
final style = container.read(themeSettingProvider).colorStyle;
|
2026-09-05 20:09:39 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
container.read(genColorSchemeProvider(Brightness.light)),
|
2026-10-16 14:55:07 +08:00
|
|
|
seededColorScheme(
|
2026-09-05 20:09:39 +08:00
|
|
|
seedColor: lightSeed,
|
|
|
|
|
brightness: Brightness.light,
|
2026-10-16 22:42:17 +08:00
|
|
|
style: style,
|
2026-09-05 20:09:39 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
expect(
|
|
|
|
|
container.read(genColorSchemeProvider(Brightness.dark)),
|
2026-10-16 14:55:07 +08:00
|
|
|
seededColorScheme(
|
2026-09-05 20:09:39 +08:00
|
|
|
seedColor: darkSeed,
|
|
|
|
|
brightness: Brightness.dark,
|
2026-10-16 22:42:17 +08:00
|
|
|
style: style,
|
2026-09-05 20:09:39 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-25 03:57:04 +08:00
|
|
|
test('pure black darkens only the dark scheme and keeps surface order', () {
|
|
|
|
|
final container = ProviderContainer();
|
|
|
|
|
addTearDown(container.dispose);
|
|
|
|
|
final light = container.read(genColorSchemeProvider(Brightness.light));
|
|
|
|
|
container
|
|
|
|
|
.read(themeSettingProvider.notifier)
|
|
|
|
|
.update((state) => state.copyWith(pureBlack: true));
|
|
|
|
|
|
|
|
|
|
expect(container.read(genColorSchemeProvider(Brightness.light)), light);
|
|
|
|
|
|
|
|
|
|
final dark = container.read(genColorSchemeProvider(Brightness.dark));
|
|
|
|
|
final tones = [
|
|
|
|
|
dark.surfaceContainerLowest,
|
|
|
|
|
dark.surface,
|
|
|
|
|
dark.surfaceDim,
|
|
|
|
|
dark.surfaceContainerLow,
|
|
|
|
|
dark.surfaceContainer,
|
|
|
|
|
dark.surfaceContainerHigh,
|
|
|
|
|
dark.surfaceContainerHighest,
|
|
|
|
|
].map((color) => Hct.fromInt(color.toARGB32()).tone).toList();
|
|
|
|
|
|
|
|
|
|
expect(dark.surface, Colors.black);
|
|
|
|
|
expect(tones, orderedEquals([...tones]..sort()));
|
|
|
|
|
expect(tones[3], greaterThan(tones[1]));
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
test('genColorScheme falls back to the accent color without a seed', () {
|
|
|
|
|
const accent = Color(0xFFFF0000);
|
|
|
|
|
final container = ProviderContainer();
|
|
|
|
|
addTearDown(container.dispose);
|
|
|
|
|
container
|
|
|
|
|
.read(dynamicColorProvider.notifier)
|
|
|
|
|
.seed(lightSeed: null, darkSeed: null, accentColor: accent);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
container.read(genColorSchemeProvider(Brightness.light)),
|
2026-10-16 14:55:07 +08:00
|
|
|
seededColorScheme(
|
2026-09-05 20:09:39 +08:00
|
|
|
seedColor: accent,
|
|
|
|
|
brightness: Brightness.light,
|
2026-10-16 22:42:17 +08:00
|
|
|
style: container.read(themeSettingProvider).colorStyle,
|
2026-09-05 20:09:39 +08:00
|
|
|
),
|
|
|
|
|
);
|
2026-08-05 10:57:40 +08:00
|
|
|
});
|
|
|
|
|
}
|