skip to Main Content

i have a problem to reducing the size of the textbutton
enter image description here
around the blute text is the size that i want to reduce to it’s child which is a containar that include text() as it’s child

                      childeren:[
                       .
                       .
                       .
                       TextButton(
                        onPressed: () => Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => const LoginModal(),
                          ),
                        ),
                        child: Container(
                          padding: const EdgeInsets.only(bottom: 0.5),
                          decoration: const BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                color: cprimary,
                                width: 1,
                              ),
                            ),
                          ),
                          child: const Text(
                            'قوانین و مقررات',
                            style: TextStyle(
                                color: cprimary,
                                fontSize: 12,
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                      ),

i try wrapping expanded and sized box and minimum size in style !
if you have info , happy to hear from you guys !

2

Answers


  1. Why don’t you consider RichText.?

    RichText(
            text: TextSpan(
              text: 'Click here to visit our website',
              style: TextStyle(
                color: Colors.black,
                fontSize: 18.0,
              ),
              children: <TextSpan>[
                TextSpan(
                  text: ' قوانین و مقررات',
                  style: TextStyle(
                    color: Colors.blue,
                    decoration: TextDecoration.underline,
                  ),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => const LoginModal(),
                          ),
                        );
                    },
                ),
              ],
            ),
          ),
    

    or you can use GestureDetector

        GestureDetector(
       child: Text('Text here'),
    onTap: () {
                print('Tapped');
              },
    )
    
    Login or Signup to reply.
  2. You can set tapTargetSize and padding to the TextButton as below:

    TextButton(
      ...
      style: TextButton.styleFrom(
        tapTargetSize: MaterialTapTargetSize.shrinkWrap,
        padding: EdgeInsets.zero, // or other value
      ),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search