【 Flutter 】Flutter を 基礎 から 学習 ( Material ComponentsとiOS-Style ) part125 Material Components

基礎 から 学ぶ Flutter 」という書籍で  学習 したことを ブログでアウトプットしていこうと思います。今回は Material ComponentsとiOS-Style ( part125 )です。

前回

【 Flutter 】Flutter を 基礎 から 学習 ( Material ComponentsとiOS-Style ) part124 Material Components

引き続き、Material Componentsについて学びます。

AppBar

AppBarウィジェットはScaffoldウィジェットのappBarで指定します。

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(home: new MyHomePage()));
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  bool dark = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: dark ? ThemeData.dark() : ThemeData.light(),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Toggle theme sample'),
          // AppBarの左側にボタンが配置されます。
          leading: IconButton(
            icon: Icon(Icons.add),
            onPressed: () {},
          ),
          // AppBarの右側にボタンが配置されます。
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.group),
              onPressed: () {},
            )
          ],
          // AppBarの下の部分のを担当します。
          // PreferredSizeウィジェットはchildの高さの影響を受けません。
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(50),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Bottom',
                style: TextStyle(fontSize: 32),
              ),
            ),
          ),
          // AppBarとbody部分との影の深さ(z軸)を指定します。
          elevation: 20,
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              setState(() => dark = !dark);
            },
            child: Text('Toggle theme'),
          ),
        ),
      ),
    );
  }
}

 

最後に

コンテンツヘッダーに相当する部分ですよね。
Scaffold・・・学習を始めて何度入力したことか。

今日はここまで!