如何覆盖悬停时的InputDecorationTheme边框颜色?

问题描述 投票:0回答:1

我尝试使用 Material theme builder 使用

#EC6164
作为源颜色来生成主题,但配色方案的
onError
属性的输出是
Color(0xffffffff)
(白色)。现在出错的文本字段边框的输出颜色是白色,如下面的屏幕录制

enter image description here

我有这个主题设置,如何在不直接更改材质主题生成器提供的颜色主题的情况下覆盖悬停时的错误颜色?

  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,
      );

flutter dart material-design
1个回答
0
投票

将 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',
        ),
      ),
    )
© www.soinside.com 2019 - 2024. All rights reserved.