shadcn_ui-theme
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShadcn UI — Theme Data
Shadcn UI — 主题数据
Instructions
使用说明
Theme and color scheme are defined by and . Supported scheme names: blue, gray, green, neutral, orange, red, rose, slate, stone, violet, yellow, zinc.
ShadThemeDataShadColorScheme主题与配色方案由和定义。支持的方案名称包括:blue、gray、green、neutral、orange、red、rose、slate、stone、violet、yellow、zinc。
ShadThemeDataShadColorSchemeBasic usage
基础用法
dart
import 'package:shadcn_ui/shadcn_ui.dart';
return ShadApp(
darkTheme: ShadThemeData(
brightness: Brightness.dark,
colorScheme: const ShadSlateColorScheme.dark(),
),
child: ...,
);dart
import 'package:shadcn_ui/shadcn_ui.dart';
return ShadApp(
darkTheme: ShadThemeData(
brightness: Brightness.dark,
colorScheme: const ShadSlateColorScheme.dark(),
),
child: ...,
);Override theme properties
覆盖主题属性
Override specific properties of the color scheme or component themes:
dart
ShadApp(
darkTheme: ShadThemeData(
brightness: Brightness.dark,
colorScheme: const ShadSlateColorScheme.dark(
background: Colors.blue,
),
primaryButtonTheme: const ShadButtonTheme(
backgroundColor: Colors.cyan,
),
),
...
);For fully custom schemes, extend and pass all required properties.
ShadColorScheme覆盖配色方案或组件主题的特定属性:
dart
ShadApp(
darkTheme: ShadThemeData(
brightness: Brightness.dark,
colorScheme: const ShadSlateColorScheme.dark(
background: Colors.blue,
),
primaryButtonTheme: const ShadButtonTheme(
backgroundColor: Colors.cyan,
),
),
...
);如需完全自定义方案,可继承并传入所有必填属性。
ShadColorSchemeTheme switcher with ShadColorScheme.fromName
使用ShadColorScheme.fromName实现主题切换器
Use to let users change the color scheme:
ShadColorScheme.fromNamedart
final shadThemeColors = [
'blue', 'gray', 'green', 'neutral', 'orange', 'red', 'rose',
'slate', 'stone', 'violet', 'yellow', 'zinc',
];
final lightColorScheme = ShadColorScheme.fromName('blue');
final darkColorScheme = ShadColorScheme.fromName('slate', brightness: Brightness.dark);Use a (or similar) with these names and rebuild the app with the chosen scheme via your state management.
ShadSelect<String>使用让用户切换配色方案:
ShadColorScheme.fromNamedart
final shadThemeColors = [
'blue', 'gray', 'green', 'neutral', 'orange', 'red', 'rose',
'slate', 'stone', 'violet', 'yellow', 'zinc',
];
final lightColorScheme = ShadColorScheme.fromName('blue');
final darkColorScheme = ShadColorScheme.fromName('slate', brightness: Brightness.dark);搭配(或类似组件)展示这些名称,并通过状态管理工具重建应用以应用所选方案。
ShadSelect<String>Custom colors
自定义颜色
Add custom colors via the parameter on the color scheme:
customdart
return ShadApp(
theme: ShadThemeData(
colorScheme: const ShadZincColorScheme.light(
custom: {
'myCustomColor': Color.fromARGB(255, 177, 4, 196),
},
),
),
);Access:
ShadTheme.of(context).colorScheme.custom['myCustomColor']!Or add an extension:
dart
extension CustomColorExtension on ShadColorScheme {
Color get myCustomColor => custom['myCustomColor']!;
}Then use:
ShadTheme.of(context).colorScheme.myCustomColor通过配色方案的参数添加自定义颜色:
customdart
return ShadApp(
theme: ShadThemeData(
colorScheme: const ShadZincColorScheme.light(
custom: {
'myCustomColor': Color.fromARGB(255, 177, 4, 196),
},
),
),
);访问方式:
ShadTheme.of(context).colorScheme.custom['myCustomColor']!或添加扩展方法:
dart
extension CustomColorExtension on ShadColorScheme {
Color get myCustomColor => custom['myCustomColor']!;
}之后可通过以下方式使用:
ShadTheme.of(context).colorScheme.myCustomColor