在Flutter中将图像对齐到左上角

12

我对Flutter还比较陌生,无法弄清如何对齐一个包含图片的子小部件。目前为止,我已尝试了以下方法:

@override
Widget build(BuildContext context) {
  return Scaffold(
  appBar: AppBar(
    title: Text(widget.username),
    backgroundColor: new Color(0xFF24292E),
  ),
  body: Center(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Image.asset(
          'assets/profile.png', width: 100.0, height: 100.0,
        ),
      ],
    ),
  ),
);
}

图片目前位于屏幕中心的顶部。我该如何将其相对于屏幕移动到左上角?谢谢。

1个回答

11

你已经将列居中了,这就是为什么其中的所有内容都居中的原因。只需移除顶层的Center()小部件,你的图片就会被顶部左对齐。

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text(widget.username),
      backgroundColor: new Color(0xFF24292E),
    ),
    body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Image.asset(
          'assets/profile.png', width: 100.0, height: 100.0,
        ),
      ],
    ),
  );
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接