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

fal*_*ide 11 dart flutter flutter-layout

我对颤振很陌生,无法弄清楚如何对齐我的一个包含图像的子小部件。这是我迄今为止尝试过的:

@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,
        ),
      ],
    ),
  ),
);
}
Run Code Online (Sandbox Code Playgroud)

然而,图像停留在屏幕的中心顶部。如何将其移动到相对于屏幕的左上角?谢谢。

her*_*ert 10

您已将列居中,这就是为什么其中的所有内容都居中的原因。只需删除顶级 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,
        ),
      ],
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)