【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part59 Multi-child layout widgets

基礎 から 学ぶ Flutter 」という書籍で  学習 したことを ブログでアウトプットしていこうと思います。今回は ウィジェット編 ( part59 )です。

前回

【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part58 Multi-child layout widgets

引き続き、Multi-child layout widgetsについて学びます。

Multi-child layout widgets

Tableウィジェット

本書ではこのTableウィジェットについてのコードが手厚く記述されています。
後続のプロパティについてもたくさん紹介されているところを見ると、かなりの頻度で使用するウィジェットであることが推測されます。

Tableウィジェットは子ウィジェットのサイズについて一括して管理してくれるすごいウィジェットです。

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _State();
  }
}

class _State extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text('テスト中です。'),
      ),
      body: Container(
        child: Table(
          border: TableBorder.all(),
          defaultVerticalAlignment: TableCellVerticalAlignment.middle,
          children: <TableRow>[
            // 1行目
            TableRow(children: <Widget>[
              box(
                  height: 100.0,
                  color: Colors.black,
                  txt: "Row 1 \n Element 1"),
              box(height: 50.0, color: Colors.green, txt: "Row 1 \n Element 2"),
              box(height: 50.0, color: Colors.amber, txt: "Row 1 \n Element 3")
            ]),
            // 2行目
            TableRow(children: <Widget>[
              box(height: 48.0, color: Colors.blue, txt: "Row 2 \n Element 1"),
              box(
                  height: 48.0,
                  color: Colors.deepPurple,
                  txt: "Row 2 \n Element 2"),
              box(height: 100.0, color: Colors.red, txt: "Row 2 \n Element 3")
            ]),
          ],
        ),
      ),
    ));
  }

  Widget box(
      {double height = 120, Color color = Colors.green, String txt = "0"}) {
    return Container(
        margin: const EdgeInsets.all(2),
        height: height,
        color: color,
        child: Text(txt));
  }
}

なんか急ににぎやかな感じになりましたね(笑

最後に

しばらくこのウィジェットの学習になりそうです。

そういえばFlutter SDK 2.8が出たそうですね!
どんどん進化してます。追いつけるかしら?

今日はここまで!