Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何覆盖单个小部件的主题?_Flutter_Textfield - Fatal编程技术网

Flutter 如何覆盖单个小部件的主题?

Flutter 如何覆盖单个小部件的主题?,flutter,textfield,Flutter,Textfield,我的颤振应用程序有一个主题,在文本字段周围添加边框: ThemeData( ... inputDecorationTheme: InputDecorationTheme( focusedBorder: OutlineInputBorder( borderSide: BorderSide(width: 1.0), ), enabledBorder: OutlineInputBorder(

我的颤振应用程序有一个主题,在文本字段周围添加边框:

ThemeData(
    ...
    inputDecorationTheme: InputDecorationTheme(
        focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(width: 1.0),
        ),
        enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(width: 1.0),
        ),
    )
但是,我确实有一个不需要边框的文本字段,因此我尝试覆盖文本字段中的边框:

TextField(
    decoration: InputDecoration.collapsed(
        hintText: _hintText,
        border: InputBorder.none,
      ),
    controller: _textController,
),
但我还是要去边境?下面是部分图像。“请输入!”字段使用主题默认值,“问题”字段是我试图覆盖的字段


用小部件包装要覆盖的小部件,并为数据属性放置一个新的主题数据小部件

return MaterialApp(
  theme: ThemeData(
    primarySwatch: Colors.orange,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),
  home: Scaffold(
    body: Column(children: [
      TextFormField(), // Takes the theme of the overall MaterialApp
      Theme(
        data: ThemeData(
          primarySwatch: Colors.blue,
        ),
        child: TextFormField(), // Takes the theme of its direct parent
      ),
    ]),
  ),
);

这个基本示例只是更改颜色,所以可以使用您喜欢的任何主题数据。

用小部件包装您要覆盖的主题数据,并为数据属性放置一个新的主题数据小部件

return MaterialApp(
  theme: ThemeData(
    primarySwatch: Colors.orange,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),
  home: Scaffold(
    body: Column(children: [
      TextFormField(), // Takes the theme of the overall MaterialApp
      Theme(
        data: ThemeData(
          primarySwatch: Colors.blue,
        ),
        child: TextFormField(), // Takes the theme of its direct parent
      ),
    ]),
  ),
);
这个基本示例只是更改颜色,所以可以使用任何您喜欢的主题数据