dart - 在 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,
),
],
),
),
);
}
然而,图像停留在屏幕的中央顶部。如何将其相对于屏幕移动到左上角?谢谢。
解决方案
您已使列居中,这就是为什么其中的所有内容都居中的原因。只需删除顶级 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,
),
],
),
);
}
推荐阅读
- android - 在 Android 上使用 Doze 模式进行自动化测试
- c# - 加密和解密字符串 当前的最佳实践
- xml - 使用 XSLT 解析自动生成的 XML
- makefile - 从 gnu make 的列表中删除带图案的前缀
- java - Java 8 例外:com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer 没有默认(无 arg)构造函数
- java - 尝试使用 getServletContext().getRealPath() 读取文件时出现 FileNotFound 异常
- matrix - 检查矩阵 ocaml 中的所有值
- javascript - React Native - 带有警报的 BackHandler
- tensorflow - 将 tf 保存的模型转换为 tflite 时出现转换错误
- jquery - Ionic 3 jQuery-snapPuzzle 插件