两列两行颤振布局

时间:2020-06-24 17:30:27

标签: flutter dart

我需要帮助来构建如下图所示的布局

enter image description here

我的代码在下面给出

Container(
  child: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Row(
      children: <Widget>[
        Flexible(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                color: Colors.black,
                alignment: Alignment.topLeft,
                child: Image.network(
                  'https://images.freeimages.com/images/large-previews/13f/natal-sofia-4-1431300.jpg',
                  width: 200,
                  height: 200,
                ),
              ),
              Container(
                child: Text("Image Text", style: Theme.of(context).textTheme.bodyText1),
              ),
            ],
          ),
        ),
        Flexible(
          child: Container(
            padding: EdgeInsets.only(left: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Text(
                  'Heading',
                  style: Theme.of(context).textTheme.headline1,
                ),
                SizedBox(
                  height: 4,
                ),
                Text(
                  'Value',
                  style: Theme.of(context).textTheme.headline5,
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  ),
);

它正在生成如下所示的UI。

enter image description here

如何将第二列字段对齐到顶部而不是中间?

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

尝试将crossAxisAlignment: CrossAxisAlignment.start,添加到Row

答案 1 :(得分:0)

这是一个完整的例子。

import 'package:flutter/material.dart';

class RowAndColumn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width;
    return Scaffold(
      body: Row(
        children: <Widget>[
          const SizedBox(width: 16),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                const SizedBox(height: 16),
                Expanded(
                  child: Container(
                    decoration: BoxDecoration(
                      border: Border.all(
                        color: Colors.black,
                      ),
                    ),
                  ),
                ),
                const SizedBox(height: 16),
                Container(
                  height: 56,
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                  ),
                ),
                const SizedBox(height: 16),
              ],
            ),
          ),
          const SizedBox(width: 16),
          SizedBox(
            width: width / 2,
            child: Column(
              children: <Widget>[
                const SizedBox(height: 16),
                Container(
                  height: 60,
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                  ),
                ),
                const SizedBox(height: 16),
                Container(
                  height: 60,
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                  ),
                ),
                const SizedBox(width: 16),
              ],
            ),
          ),
          const SizedBox(width: 16),
        ],
      ),
    );
  }
}

答案 2 :(得分:0)

crossAxisAlignment:CrossAxisAlignment.start,将其添加到您打开的第一行以获得更好的视图,您也可以尝试mainAxisAlignment