Change size of text according to screen width in Flutter

I want the text size to remain the same however i want it to be bigger when on a larger screen width device.

MediaQueryData queryData;

  @override
  Widget build(BuildContext context) {
    queryData = MediaQuery.of(context);
    Text("Hello.",
        style: TextStyle(
        fontSize: queryData.size.width, color: Colors.white),
 ),

}

However, it became so big when i tried queryData.size.width. in this case i want the text to expand according to different devices screens.

left: ipad, right: iphone X

1 answer

  • answered 2019-05-22 04:20 Samyak Jain

    We can use view vw and vh unit to provide font-size, which will make your text more visible with different viewport size.

    h1 {
      font-size: 5.9vw;
    }
    h2 {
      font-size: 3.0vh;
    }
    p {
      font-size: 2vmin;
    }
    
    
    1vw = 1% of viewport width
    1vh = 1% of viewport height
    1vmin = 1vw or 1vh, whichever is smaller
    1vmax = 1vw or 1vh, whichever is larger