style(theme): 客户端切换深色视觉风格
This commit is contained in:
1 parent
295c21513c
commit
4bc04fd8ae
75 files changed
+732
-330
No files matched your search
@@ -4,13 +4,15 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
|
||||
void main() {
|
||||
test('should_expose_the_k20_spacing_and_type_scale', () {
|
||||
test('should_expose_dark_theme_radius_and_spacing_scale', () {
|
||||
expect(AppDimens.pageHorizontal, 16);
|
||||
expect(AppDimens.cardRadius, 16);
|
||||
expect(AppDimens.coverRadius, 16);
|
||||
expect(AppDimens.authCardRadius, 20);
|
||||
expect(AppDimens.cardRadius, 12);
|
||||
expect(AppDimens.coverRadius, 12);
|
||||
expect(AppDimens.authCardRadius, 12);
|
||||
expect(AppDimens.buttonRadius, 10);
|
||||
expect(AppDimens.inputRadius, 10);
|
||||
expect(AppDimens.chipRadius, 6);
|
||||
expect(AppDimens.pillRadius, 999);
|
||||
expect(AppDimens.buttonRadius, 999);
|
||||
expect(AppDimens.caption, 12);
|
||||
expect(AppDimens.body, 14);
|
||||
expect(AppDimens.listTitle, 15);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/app.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/core/theme/app_theme.dart';
|
||||
|
||||
double _contrast(Color foreground, Color background) {
|
||||
@@ -16,44 +17,59 @@ double _contrast(Color foreground, Color background) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('should_expose_light_warm_orange_tokens', () {
|
||||
expect(AppColors.blue, const Color(0xFFFF7A1A));
|
||||
expect(AppColors.bluePressed, const Color(0xFFFF6A00));
|
||||
expect(AppColors.secondary, const Color(0xFFFF6A8A));
|
||||
expect(AppColors.ink, const Color(0xFFFFF8F0));
|
||||
expect(AppColors.surfaceTop, const Color(0xFFFFE9D6));
|
||||
expect(AppColors.card, const Color(0xFFFFFFFF));
|
||||
expect(AppColors.onSurface, const Color(0xFF1F1B16));
|
||||
expect(AppColors.muted, const Color(0xFF8C837B));
|
||||
expect(AppColors.subtle, const Color(0xFFB3AAA1));
|
||||
expect(AppColors.border, const Color(0xFFF0E4D6));
|
||||
expect(AppColors.badgePink, const Color(0xFFFFE3EC));
|
||||
expect(AppColors.badgePinkText, const Color(0xFFFF6A8A));
|
||||
test('should_expose_dark_visual_tokens', () {
|
||||
expect(AppColors.blue, const Color(0xFFFF6B2C));
|
||||
expect(AppColors.bluePressed, const Color(0xFFE55A1F));
|
||||
expect(AppColors.secondary, const Color(0xFF22D3EE));
|
||||
expect(AppColors.ink, const Color(0xFF0B1020));
|
||||
expect(AppColors.card, const Color(0xFF151B2E));
|
||||
expect(AppColors.raised, const Color(0xFF1C2436));
|
||||
expect(AppColors.border, const Color(0x0FFFFFFF));
|
||||
expect(AppColors.onSurface, const Color(0xEBFFFFFF));
|
||||
expect(AppColors.muted, const Color(0xA3FFFFFF));
|
||||
expect(AppColors.subtle, const Color(0x61FFFFFF));
|
||||
expect(AppDimens.cardRadius, 12);
|
||||
expect(AppDimens.buttonRadius, 10);
|
||||
expect(AppDimens.inputRadius, 10);
|
||||
expect(AppDimens.chipRadius, 6);
|
||||
});
|
||||
|
||||
test('should_keep_primary_text_readable_on_warm_background', () {
|
||||
test('should_keep_primary_and_secondary_text_readable_on_dark', () {
|
||||
expect(
|
||||
_contrast(AppColors.onSurface, AppColors.ink),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
expect(
|
||||
_contrast(AppColors.onSurface, AppColors.card),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
expect(_contrast(AppColors.muted, AppColors.card), greaterThanOrEqualTo(3));
|
||||
expect(_contrast(AppColors.gold, AppColors.ink), greaterThanOrEqualTo(3));
|
||||
expect(_contrast(AppColors.blue, AppColors.ink), greaterThanOrEqualTo(3));
|
||||
});
|
||||
|
||||
test('should_use_light_color_scheme_and_dark_system_icons', () {
|
||||
final theme = AppTheme.light();
|
||||
test('should_use_dark_color_scheme_and_light_system_icons', () {
|
||||
final theme = AppTheme.dark();
|
||||
|
||||
expect(theme.brightness, Brightness.light);
|
||||
expect(theme.brightness, Brightness.dark);
|
||||
expect(theme.colorScheme.primary, AppColors.blue);
|
||||
expect(theme.colorScheme.onPrimary, AppColors.onPrimary);
|
||||
expect(theme.colorScheme.secondary, AppColors.secondary);
|
||||
expect(theme.colorScheme.surface, AppColors.ink);
|
||||
expect(theme.colorScheme.onSurface, AppColors.onSurface);
|
||||
expect(theme.colorScheme.outline, AppColors.border);
|
||||
expect(theme.scaffoldBackgroundColor, AppColors.ink);
|
||||
expect(theme.appBarTheme.systemOverlayStyle, SystemUiOverlayStyle.dark);
|
||||
expect(theme.appBarTheme.backgroundColor, AppColors.card);
|
||||
expect(theme.appBarTheme.systemOverlayStyle, SystemUiOverlayStyle.light);
|
||||
expect(theme.cardTheme.elevation, 0);
|
||||
expect(theme.dialogTheme.backgroundColor, AppColors.raised);
|
||||
expect(theme.bottomNavigationBarTheme.backgroundColor, AppColors.bar);
|
||||
expect(theme.inputDecorationTheme.fillColor, AppColors.input);
|
||||
});
|
||||
|
||||
test('should_use_ink_navigation_bar_without_contrast_scrim', () {
|
||||
test('should_use_ink_navigation_bar_with_light_icons', () {
|
||||
expect(appSystemOverlayStyle.statusBarColor, Colors.transparent);
|
||||
expect(appSystemOverlayStyle.statusBarIconBrightness, Brightness.light);
|
||||
expect(appSystemOverlayStyle.systemNavigationBarColor, AppColors.ink);
|
||||
expect(
|
||||
appSystemOverlayStyle.systemNavigationBarDividerColor,
|
||||
@@ -61,20 +77,20 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
appSystemOverlayStyle.systemNavigationBarIconBrightness,
|
||||
Brightness.dark,
|
||||
Brightness.light,
|
||||
);
|
||||
expect(appSystemOverlayStyle.systemNavigationBarContrastEnforced, isFalse);
|
||||
|
||||
final sheetTheme = AppTheme.light().bottomSheetTheme;
|
||||
final sheetTheme = AppTheme.dark().bottomSheetTheme;
|
||||
expect(sheetTheme.backgroundColor, Colors.transparent);
|
||||
expect(sheetTheme.modalBackgroundColor, Colors.transparent);
|
||||
expect(sheetTheme.surfaceTintColor, Colors.transparent);
|
||||
});
|
||||
|
||||
test('should_expose_page_gradient_and_soft_card_shadow', () {
|
||||
test('should_expose_flat_page_gradient_without_card_shadow', () {
|
||||
expect(AppTheme.pageGradient.colors, [AppColors.surfaceTop, AppColors.ink]);
|
||||
expect(AppTheme.cardShadow.color, AppColors.cardShadow);
|
||||
expect(AppTheme.cardShadow.blurRadius, 18);
|
||||
expect(AppTheme.cardShadow.offset, const Offset(0, 6));
|
||||
expect(AppTheme.cardShadow.blurRadius, 0);
|
||||
expect(AppTheme.cardShadow.offset, Offset.zero);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/remote/auth_api.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_theme.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/watch_records/watch_records_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
import '../support/fake_http_adapter.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
testWidgets('should_render_material_app_with_dark_default_theme', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
darkTheme: AppTheme.dark(),
|
||||
themeMode: ThemeMode.dark,
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
key: const Key('dark-smoke-scaffold'),
|
||||
appBar: AppBar(title: const Text('Dark')),
|
||||
body: Card(
|
||||
key: const Key('dark-smoke-card'),
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
'Primary',
|
||||
style: TextStyle(color: AppColors.onSurface),
|
||||
),
|
||||
subtitle: Text('Muted', style: TextStyle(color: AppColors.muted)),
|
||||
trailing: Text('128', style: TextStyle(color: AppColors.gold)),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: 0,
|
||||
destinations: const [
|
||||
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
|
||||
NavigationDestination(icon: Icon(Icons.person), label: 'Mine'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(
|
||||
find.byKey(const Key('dark-smoke-scaffold')),
|
||||
);
|
||||
final theme = Theme.of(context);
|
||||
expect(theme.brightness, Brightness.dark);
|
||||
expect(theme.scaffoldBackgroundColor, AppColors.ink);
|
||||
expect(theme.appBarTheme.backgroundColor, AppColors.card);
|
||||
expect(theme.cardTheme.color, AppColors.card);
|
||||
|
||||
final card = tester.widget<Card>(find.byKey(const Key('dark-smoke-card')));
|
||||
expect(card.color ?? theme.cardTheme.color, AppColors.card);
|
||||
expect(find.text('Primary'), findsOneWidget);
|
||||
expect(find.text('Muted'), findsOneWidget);
|
||||
expect(find.text('128'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_render_watch_records_page_on_dark_surface', (
|
||||
tester,
|
||||
) async {
|
||||
final auth = AuthController(
|
||||
AuthApi(
|
||||
ApiClient(
|
||||
baseUrl: 'http://127.0.0.1:1',
|
||||
adapter: FakeHttpAdapter(
|
||||
(_) async =>
|
||||
FakeHttpResponse('{"code":0,"message":"ok","data":null}'),
|
||||
),
|
||||
),
|
||||
),
|
||||
AuthSessionStore(),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ChangeNotifierProvider<AuthController>.value(
|
||||
value: auth,
|
||||
child: MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
darkTheme: AppTheme.dark(),
|
||||
themeMode: ThemeMode.dark,
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const WatchRecordsPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scaffold = tester.widget<Scaffold>(
|
||||
find.byKey(const Key('watch-records-page')),
|
||||
);
|
||||
expect(scaffold.backgroundColor, AppColors.ink);
|
||||
expect(find.byKey(const Key('auth-gate-panel')), findsOneWidget);
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user