[Flutter]DataTableの左右のマージンを設定するには?

Flutter

どうも、ちょげ(@chogetarou)です。

DataTableの左右のマージンを設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

DataTableの左右のマージンを設定するには、引数「horizontalMargin」を使います。

具体的には、DataTableの引数「horizontalMargin」に左右のマージンを指定します。

DataTable(
  horizontalMargin: マージン,
  columns: [・・・],
  rows: [・・・],
),

DataTableの引数「horizontalMargin」に指定した値が、DataTableの左右のマージンになります。

使用例

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: DataTable(
            horizontalMargin: 50,
            columns: [
              DataColumn(
                label: Text('名前'),
              ),
              DataColumn(
                label: Text('年齢'),
              ),
              DataColumn(
                label: Text('性別'),
              ),
            ],
            rows: [
              DataRow(
                cells: [
                  DataCell(Text('太郎')),
                  DataCell(Text('19')),
                  DataCell(Text('男')),
                ],
              ),
              DataRow(
                cells: [
                  DataCell(Text('さゆり')),
                  DataCell(Text('24')),
                  DataCell(Text('女')),
                ],
              ),
              DataRow(
                cells: [
                  DataCell(Text('吾郎')),
                  DataCell(Text('34')),
                  DataCell(Text('男')),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました