flutter中如何根据图标按钮的父控件高度设置图标按钮的飞溅半径

k7fdbhmy  于 2022-11-17  发布在  Flutter
关注(0)|答案(2)|浏览(206)

我创建了一个customTextfield并将IconButton作为后缀图标放置,
当我点击图标按钮时,它飞溅半径比文本框大,
这里我想固定飞溅半径的高度基于它的父母..像如果它是100高度的容器内..它必须根据它设置...
这是我代码

class CustomTextField extends StatelessWidget {

  final String hint;
  final bool isitpassword;
  final TextEditingController controller;
  const CustomTextField({Key? key,required this.hint,this.isitpassword=false,required this.controller}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 10.0),
      child: Container(
          padding: EdgeInsets.symmetric(horizontal: 20),
          decoration: BoxDecoration(
            color: Colors.grey,
            borderRadius: BorderRadius.circular(20),
          ),

          child: TextField(
            style: TextStyle(
              fontSize: 20,color: Colors.white,),

            controller: controller,
            obscureText: isitpassword,
            decoration: InputDecoration(

              border: InputBorder.none,
              hintText: hint,
              suffixIcon: IconButton(
//what spread radius to set for better view
icon: Icon(Icons.close,color: Colors.white,),onPressed: (){
                controller.text='';
              },),

            ),
          )),
    );
  }
}
lg40wkob

lg40wkob1#

您可以使用splashRadius: 48 / 2

slmsl1lt

slmsl1lt2#

您可以使用InkWell,如下所示,它将使用与其父对象相同大小:

TextField(
        style: TextStyle(
          fontSize: 20,
          color: Colors.white,
        ),
        controller: controller,
        obscureText: isitpassword,
        decoration: InputDecoration(
            border: InputBorder.none,
            hintText: hint,
            suffixIcon: InkWell(
              borderRadius: BorderRadius.circular(100),
              child: Icon(
                Icons.close,
                color: Colors.white,
              ),
              onTap: () {
                controller.text = '';
              },
            )),
      ),

100数并不重要,只要设置一个big数即可。

相关问题