Flutter for webでWebフォントを使う
使える気がするんだけど何か方法あるのかなーと思って試してみたら普通に使えばよいことがわかった。
index.htmlでWebフォントを読み込む
好きなフォントを書く
<html lang="en"> <head> <!-- ...略 --> <link href="https://fonts.googleapis.com/css?family=Gentium+Book+Basic&display=swap" rel="stylesheet"> </head> </html>
fontFamilyで指定する
あとは普通にfontFamilyで名前を指定するだけ。
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( widget.title, style: TextStyle( fontSize: 32, fontFamily: "Gentium Book Basic", fontWeight: FontWeight.bold), ), ),
こんな感じで反映される。
before | after |
---|---|
まとめ
Webフォントをそのまま使えるのは良いですね~。