种子不起作用的flutter应用程序栏背景颜色
我正在开发一个颤抖的应用程序。在此,我试图在themedata
中使用usematerial3
。因此,我使用以下代码在colorscheme
中设置颜色。
static ThemeData lightThemeData = ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.red,
),
appBarTheme: AppBarTheme(
centerTitle: true,
elevation: 2,
titleTextStyle: textTheme.titleLarge,
),
);
我已将上面的LightThemedata
在main.dart
中分配给主题属性。当我运行应用程序时,Appbar不显示合适的颜色。请检查下面的屏幕截图。
它没有显示适当的红色。有人知道,为什么会发生这种情况?
Flutter版本: 3.0.1
注意:它在Flutter v2.10.5上工作,但在3.0.1
上不使用
I am developing one app in Flutter. In this, I am trying to use useMaterial3
in ThemeData
. So I used below code to set color in colorScheme
.
static ThemeData lightThemeData = ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.red,
),
appBarTheme: AppBarTheme(
centerTitle: true,
elevation: 2,
titleTextStyle: textTheme.titleLarge,
),
);
I have assigned above lightThemeData
in Main.dart
to theme property. AppBar not showing proper color when I run the app. Please check below screenshot.
It is not showing proper Red Color. Anyone know, why this is happening?
Flutter version: 3.0.1
Note: It is working on Flutter v2.10.5 but not on 3.0.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将类似的内容用于全红色体验:
另外,您可以使用类似的情况使用:
但是请确保在使用该应用程序的每个部分,因为文档说:
我认为FromSwatch专为材料设计2。
以下是一个外部工具:
为了绝对控制颜色,在 https://m3.material.io/theme-builder#/custom
从左栏中选择您的颜色,并使用右上按钮导出结果(有一个颤音选项)。下载的文件包含完整的方案。您可以覆盖不喜欢的颜色,并直接进入主题。
You can use something like this for the full red experience:
Alternatively you can use fromSwatch like this:
But make sure to test every part of your app before using it because the documentation says:
I think fromSwatch is designed for Material Design 2.
Following contains an external tool:
For the absolute control over the colors there is a nice tool at https://m3.material.io/theme-builder#/custom
From the left bar choose your colors, and export the result using the top right button(there is a Flutter option). Downloaded file contains the full schemes. You can override the colors you don't like and feed into the theme directly.
种子颜色可直接用于创建用于主音调的音调调色板。然后,从同一音调调色板中为浅色模式和色调80分配了色调40的音调40。这些颜色都不是您使用的“主要”种子颜色的确切匹配,它将是与种子颜色相匹配的色调调色板的颜色,因为它是主要的颜色。
品牌Challange
如果您出于品牌目的需要它才能与提供的种子颜色完全匹配,则可以随时覆盖Colorscheme.Primary。使用原始种子颜色使用copywith获得。然后将该Colorscheme用作应用程序主题的输入。要额外的一步,但是它也可以正常工作,而且看起来还不错,因为对于原始颜色,其他颜色仍然可以匹配并与这种颜色保持同步。
The seed color is used directly to create the tonal palette for primary tones. The ColorScheme.primary is then assigned tone 40 for light mode and tone 80 for dark mode, from the same tonal palette. Neither of these colors will be an exact match for the "primary" seed color you used, it will be a color from a tonal palette that matches the seed color, since it is the primary one.
Branding challange
If you for branding purposes require it to exactly match the provided seed color, you can always override ColorScheme.primary you got with copyWith using the original seed color. And then use that ColorScheme as input to your apps ThemeData. A bit of an extra step, but it will work and look OK too, because for primaries the other colors will still match and be in sync with this color.
您的应用程序会生成从给定的种子颜色派生的[Colorscheme]。
使用种子颜色作为起点,构建了一组音调调色板。这些音调调色板基于材料3颜色系统,并为[Colorscheme]提供了所有所需的颜色。
或者,如果您希望任何小部件的颜色与所提供的种子颜色完全相同,则应为其提供背景和前景颜色,例如:
使用此颜色,您的Appbar将看起来像您的种子颜色一样,将其看起来确切的颜色。
Your app generates a [ColorScheme] derived from the given seedColor.
Using the seedColor as a starting point, a set of tonal palettes are constructed. These tonal palettes are based on the Material 3 Color system and provide all the needed colors for a [ColorScheme].
Alternately, if you want any of your Widgets to have the exact same color as your provided seed color, you should provide it with background and foreground color, e.g.:
using this your appbar will look the exact colors as your seed color.