LoginSignup
28
11

More than 3 years have passed since last update.

【Flutter】画面サイズに応じて文字サイズを自動で適用する方法

Posted at

この記事を読んで習得できること

画面サイズに応じて文字サイズを自動で変えることができるようになる。
結構使うことになるので備忘録として。

結論

TextFittedBox配下に置く。

sample.dart
FittedBox(
  fit: BoxFit.fitWidth,
  child: Text(
    "あああああああああああああああああああああああテトラポット",
    style: TextStyle(fontSize: 32),
  ),
),

スクリーンショット 2020-08-18 23.42.39.png

FittedBoxがなかったら

折り返したり、画面からはみ出たりして、画面がぶっ壊れてしまう。

sample.dart
Text(
  "あああああああああああああああああああああああテトラポット",
  style: TextStyle(fontSize: 32),
),

スクリーンショット 2020-08-18 23.41.56.png

なので、この方法を覚えておくといいかも。

Swiftだとどうやって書くんだっけ?
interface builderでいつも設定してたから覚えてないや…
復習しないとな…

28
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
11