首页 > 解决方案 > 去除颤动的TextField标签文本背景颜色

问题描述

代码

  Widget searchButton() {
    return TextField(
      decoration: InputDecoration(
        labelText: "Arama",
        hintText: "Ara",
       
        labelStyle: TextStyle(color: Colors.yellow,backgroundColor: Colors.red),
        hintStyle: Theme.of(context).textTheme.button,
      ),
    );
  }

我想完全去除这张图片中的背景颜色(红色)(我不是说透明的)

在此处输入图像描述

标签: flutterdart

解决方案


您不想要红色,您可以轻松地将其从标签样式中删除,labelStyle: TextStyle(color: Colors.yellow, backgroundColor: Colors.red),只需删除这一行中的背景颜色:Colors.red 。

在我的代码中,我在 Text 后面没有任何 trasprated 框,这是我的代码:

    import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Widget searchButton() {
    return TextField(
      decoration: InputDecoration(
        labelText: "Arama",
        hintText: "Ara",
        labelStyle:
            TextStyle(color: Colors.yellow),
        hintStyle: Theme.of(context).textTheme.button,
      ),
    );



}

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        
        appBar: AppBar(),
        body: Container(child: searchButton()),
      ),
    );
  }
}

推荐阅读