![見出し画像](https://assets.st-note.com/production/uploads/images/69573105/rectangle_large_type_2_34faa9b6a3b1baf09e6311cb83d4d4ef.png?width=1200)
Photo by
hamahouse
Flutter アプリ開発の道 〜その⑦_2 マテリアルデザイン アイコン編〜
前回はマテリアルデザイン テキスト編についての記事を書きました。
今回も前回に続きマテリアルデザインについての続きの記事です。
2回目はSystem iconsのアイコンを理解していこうと思います。
System iconsを利用することで自前でリソース作成・準備しなくてもアプリが開発できます。
デザイナーがいなくてもデザインがイケてるアプリを作成できることを目指せます。
System iconsの理解
System icons を理解して利用する為に、以下の公式のドキュメントをまずは一読しましょう。
https://material.io/design/iconography/system-icons.html#design-principles
System iconsで利用できるアイコン一覧
利用できるアイコンは、Googleフォントの公式サイトに記載されています。
https://fonts.google.com/icons
System iconsをサンプルプロジェクトで理解する
前回と同様にサンプルプロジェクトを利用して理解を深めていきましょう。
・
・
・
@override
Widget build(BuildContext context) {
return Scaffold(
・
・
・
body: Center(
・
・
・
child: Column(
・
・
・
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
・
・
・
↓の部分のコードを変更して検証していきます。
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
サンプルプロジェクトのデフォルト表示は↓になります。
![](https://assets.st-note.com/img/1641747397064-wDcavfijRR.png)
1行目にアイコンを挿入してみます。
挿入するアイコンは、なんとなくですが、好きな地下鉄のアイコン(Icon.subway)をチョイスしました。
children: <Widget>[
const Icon(Icons.subway),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
![](https://assets.st-note.com/img/1641747554191-GsrK0kqjae.png)
地下鉄のアイコンが表示されました。
アイコンのサイズを変更してみます。
children: <Widget>[
const Icon(Icons.subway, size: 70,),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
![](https://assets.st-note.com/img/1641747602486-N5rbpEgoe9.png)
サイズが変更されました。
色も変更してみます。
children: <Widget>[
const Icon(Icons.subway, size: 70, color: Colors.redAccent,),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
![](https://assets.st-note.com/img/1641747815223-uMY39K53Zg.png)
RichTextを利用して文字列の中に並べることも可能です。
@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
・
・
・
children: <Widget>[
RichText(
text: TextSpan(
children: [
TextSpan(
text : 'You have pushed the button this many times:',
style: textTheme.bodyText1
),
const WidgetSpan(
alignment: PlaceholderAlignment.middle,
child : Icon(Icons.subway)
),
]
),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
![](https://assets.st-note.com/img/1641748015158-hHSLfrcPDC.png)
FlutterのMaterialコンポーネントを少しずつ理解していきましょう。