0

I want the text displayed in my application to adjust the screen size. whether by using the default textTheme will produce responsive text?

Jsoon
  • 123
  • 4
  • 14
  • Does [this](https://stackoverflow.com/questions/51674962/how-to-make-text-as-big-as-the-width-allows-in-flutter) answer your question? – Just Mohit Jun 09 '21 at 04:29

3 Answers3

1

You can use flutter_screenutil package, for responsive font you can use like this

 Text(
     '16sp, will not change with the system.',
      style: TextStyle(
        color: Colors.black,
        fontSize: 16.sp, // this will make font responsive
      ),
    ),
Hemal Moradiya
  • 1,715
  • 1
  • 6
  • 26
  • can only using textTheme as below make text responsive? Text( 'Text with a background color', style: Theme.of(context).textTheme.headline6, ), – Jsoon Jun 09 '21 at 07:51
  • I didn't have any idea so I've checked with two different devices and I personally didn't find much different. Both devices it looks same. – Hemal Moradiya Jun 09 '21 at 08:24
1

if you want to have "responsive text" you can access the size of the screen with this

Size size = MediaQuery.of(context).size;

and then you have the ability to change the size of the text by doing

Center(
    child: Text(
        style: TextStyle(
            fontWeight: FontWeight.w600,
            fontSize: size.width * 0.005, //play arround with this number to get the size you want
            ),
         ),
      ),
Jaime Ortiz
  • 1,089
  • 10
  • 14
  • can only using textTheme as below make text responsive? Text( 'Text with a background color', style: Theme.of(context).textTheme.headline6, ), – Jsoon Jun 09 '21 at 07:51
0

you can make text responsive with the help of screen width.

And you should try

 fontSize: MediaQuery.of(context).size.width > 500 ?60 : MediaQuery.of(context).size.width < 300 ?40:30,

The above statement means that, when your screen width is greater than 500 then show textsize 60 if less than 300, then show textsize 30 else between 500 and 300 shows textsize 40

Mehran Ullah
  • 550
  • 4
  • 17
  • can only using textTheme as below make text responsive? Text( 'Text with a background color', style: Theme.of(context).textTheme.headline6, ), – Jsoon Jun 09 '21 at 07:51
  • Please edit your questions and explain what you want exactly - Thanks. The text Responsive means its size fit every screen size. – Mehran Ullah Jun 10 '21 at 05:07