Flutter 将柱中的图元与顶部对齐

Flutter 将柱中的图元与顶部对齐,flutter,Flutter,如何将第一列与顶部对齐 我来自Android开发背景,通常只在容器上使用gravity=“top” 但我如何在颤振中做到这一点 import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; void main() => runApp(MyApp()); class MyApp extends Statele

如何将第一列与顶部对齐

我来自Android开发背景,通常只在容器上使用
gravity=“top”

但我如何在颤振中做到这一点

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Layout Test'),
          ),
          body: ListView(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[

    // The problem is here ------> 

                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                    ],
                  ),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                ],
              )
            ],
          ),
        ));
  }

  Column _buildLongColumn() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
      ],
    );
  }
}

import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
appBar:appBar(
标题:文本(“布局测试”),
),
正文:ListView(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
//问题就在这里------>
纵队(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
],
)
],
),
));
}
列_buildLongColumn(){
返回列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
);
}
}

您只需在
行中设置
crossAxisAlignment:crossAxisAlignment.start
试试这个代码

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Layout Test'),
          ),
          body: ListView(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[

                  // The problem is here ------>

                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                    ],
                  ),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                ],
              )
            ],
          ),
        ));
  }

  Column _buildLongColumn() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
      ],
    );
  }
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
appBar:appBar(
标题:文本(“布局测试”),
),
正文:ListView(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
//问题就在这里------>
纵队(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
],
)
],
),
));
}
列_buildLongColumn(){
返回列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
);
}
}

有关行和列的详细信息

您只需在
行中设置
crossAxisAlignment:crossAxisAlignment.start
试试这个代码

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Layout Test'),
          ),
          body: ListView(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[

                  // The problem is here ------>

                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                      Icon(Icons.star_half),
                    ],
                  ),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                  _buildLongColumn(),
                ],
              )
            ],
          ),
        ));
  }

  Column _buildLongColumn() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
        Icon(Icons.star_half),
      ],
    );
  }
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
appBar:appBar(
标题:文本(“布局测试”),
),
正文:ListView(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
//问题就在这里------>
纵队(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
_buildLongColumn(),
],
)
],
),
));
}
列_buildLongColumn(){
返回列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
图标(图标。星形半),
],
);
}
}
有关行和列的详细信息

Wow so