feat(client): 三套 ThemeData 构建(挂 AppTokens,B 为 dark)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'app_tokens.dart';
|
||||
import 'app_tokens.g.dart';
|
||||
|
||||
ThemeData buildTheme(String key) {
|
||||
final t = appTokensOf(key);
|
||||
final brightness = t.isDark ? Brightness.dark : Brightness.light;
|
||||
final scheme = ColorScheme.fromSeed(
|
||||
seedColor: t.primary,
|
||||
brightness: brightness,
|
||||
).copyWith(
|
||||
primary: t.primary,
|
||||
onPrimary: t.onPrimary,
|
||||
surface: t.surface,
|
||||
error: t.danger,
|
||||
);
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: brightness,
|
||||
colorScheme: scheme,
|
||||
scaffoldBackgroundColor: t.bg,
|
||||
fontFamily: null, // 系统中文字体;字号梯度后续在组件层接入
|
||||
extensions: <ThemeExtension<dynamic>>[t],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jiu_client/core/theme/app_tokens.dart';
|
||||
import 'package:jiu_client/core/theme/themes.dart';
|
||||
|
||||
void main() {
|
||||
test('buildTheme 挂载 AppTokens 且亮暗正确', () {
|
||||
final a = buildTheme('a');
|
||||
expect(a.extension<AppTokens>(), isNotNull);
|
||||
expect(a.brightness, Brightness.light);
|
||||
expect(a.extension<AppTokens>()!.primary, const Color(0xFF2563AC));
|
||||
|
||||
final b = buildTheme('b');
|
||||
expect(b.brightness, Brightness.dark);
|
||||
expect(b.scaffoldBackgroundColor, b.extension<AppTokens>()!.bg);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user