我尝试使用 Material theme builder 使用
#EC6164
作为源颜色来生成主题,但配色方案的 onError
属性的输出是 Color(0xffffffff)
(白色)。现在出错的文本字段边框的输出颜色是白色,如下面的屏幕录制
我有这个主题设置,如何在不直接更改材质主题生成器提供的颜色主题的情况下覆盖悬停时的错误颜色?
ThemeData theme(ColorScheme colorScheme) => ThemeData(
useMaterial3: true,
brightness: colorScheme.brightness,
colorScheme: colorScheme,
textTheme: textTheme.apply(
bodyColor: colorScheme.onSurface,
displayColor: colorScheme.onSurface,
),
inputDecorationTheme: InputDecorationTheme(
// how to override the on error color
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
fillColor: Colors.purple.withOpacity(0.1),
filled: true,
),
scaffoldBackgroundColor: colorScheme.surface,
canvasColor: colorScheme.surface,
);
将 TextField 包裹在 MouseRegion 中
bool isHovered = false;
MouseRegion(
onEnter: (_) => setState(() => isHovered = true),
onExit: (_) => setState(() => isHovered = false),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: isHovered
? Colors.blue
: Colors.grey,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: isHovered
? Colors.blue
: Colors.blueAccent,
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: isHovered
? Colors.blue
: Colors.grey,
),
),
hintText: 'Hover over me',
),
),
)