Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to set icon button's splash radius based on it's parent widget height in flutter

I have created a customTextfield and placed IconButton as suffix icon,

here when I tap on icon button, its splash radius showing bigger than textfield,

here I want to fix height of splash radius based on it’s parent.. like if it is inside of container of 100height..it must be set according to it…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

here is my code

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='';
              },),

            ),
          )),
    );
  }
}

>Solution :

you can use InkWell instead like this it will take size as much as its parent:

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 = '';
              },
            )),
      ),

the 100 number is not important just set a big number.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading