feat(flutter): 应用克莱因蓝主题与印尼语适配

This commit is contained in:
Zhou Weidong committed 2026-10-17 15:58:17 +08:00
1 parent e1147cfcba
commit 10d448c8ba
31 files changed
+891 -521

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
// Author: fruit.com.cn
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/theme/app_colors.dart';
import 'package:fruitshorts/core/theme/app_theme.dart';
double _contrast(Color foreground, Color background) {
final first = foreground.computeLuminance();
final second = background.computeLuminance();
return (max(first, second) + 0.05) / (min(first, second) + 0.05);
}
void main() {
test('should_expose_approved_klein_blue_tokens', () {
expect(AppColors.blue, const Color(0xFF002FA7));
expect(AppColors.bluePressed, const Color(0xFF00227A));
expect(AppColors.blueSoft, const Color(0xFF5B7BE0));
expect(AppColors.onPrimary, const Color(0xFFFFFFFF));
});
test('should_meet_text_and_icon_contrast_when_using_theme_tokens', () {
expect(
_contrast(AppColors.onPrimary, AppColors.blue),
greaterThanOrEqualTo(4.5),
);
expect(_contrast(AppColors.blue, Colors.white), greaterThanOrEqualTo(4.5));
expect(
_contrast(AppColors.blueSoft, AppColors.ink),
greaterThanOrEqualTo(3),
);
});
test('should_use_klein_blue_in_light_and_dark_color_schemes', () {
for (final theme in [AppTheme.light(), AppTheme.dark()]) {
expect(theme.colorScheme.primary, AppColors.blue);
expect(theme.colorScheme.onPrimary, AppColors.onPrimary);
}
});
testWidgets('should_expose_klein_blue_through_widget_theme', (tester) async {
late ThemeData applied;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.dark(),
home: Builder(
builder: (context) {
applied = Theme.of(context);
return const SizedBox.shrink();
},
),
),
);
expect(applied.colorScheme.primary, AppColors.blue);
expect(applied.colorScheme.onPrimary, AppColors.onPrimary);
});
}
+25
View File
@@ -0,0 +1,25 @@
// Author: fruit.com.cn
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('should_use_theme_tokens_when_lib_code_is_scanned_for_legacy_blue', () {
final pattern = RegExp(
r'0xFF2F7BFF|0xff2F7BFF|0xFF8FB4FF|0xff8FB4FF|(?<!App)Colors\.blue\b',
);
final violations = <String>[];
for (final entity in Directory('lib').listSync(recursive: true)) {
if (entity is! File || !entity.path.endsWith('.dart')) continue;
final lines = entity.readAsLinesSync();
for (var index = 0; index < lines.length; index++) {
if (pattern.hasMatch(lines[index])) {
violations.add('${entity.path}:${index + 1}: ${lines[index].trim()}');
}
}
}
expect(violations, isEmpty, reason: violations.join('\n'));
});
}