flutter - 如何在颤动中固定背景图像的大小和位置?
问题描述
Widget build(BuildContext context){
var height2 = AppBar().preferredSize.height;
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
Image(
image: AssetImage("assets/oral_structure.png"),
fit: BoxFit.fill
),
Padding(
padding: EdgeInsets.only(top:100, left: 100),
child: Container(
height: 60,
width: 60,
child: FlatButton(
child: Text('ㅂ', style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold)),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => B()),);
},
)
),
),
以上是我的代码的一部分。我正在制作的应用程序是将适当的按钮放置在背景图像顶部的位置。但是,如果您进行上述代码,则按钮的位置和图像的位置会根据智能手机的屏幕尺寸而有所不同。固定高度和宽度也是如此。怎么没有办法?
解决方案
@override
Widget build(BuildContext context) {
return Scaffold(
key: v.scaffoldKey,
body: Stack(
children: [
getBackgroundLight(),
],
),
);
}
Widget getBackgroundLight() {
return Stack(
children: [
Image.asset('assets/background.jpg', width: double.infinity),
Transform.rotate(
angle: -SizeConfig.calculateBlockVertical(180) *
(math.pi / SizeConfig.calculateBlockVertical(180)),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.center,
end: Alignment.bottomCenter,
colors: [
Get.theme.scaffoldBackgroundColor,
Get.theme.scaffoldBackgroundColor.withOpacity(0.5),
],
),
),
),
),
],
);
}
推荐阅读
- dart - 设置堆栈布局小部件的高度
- java - 如何从 HttpServeletRequest 对象中检索 @RequestBody 注释的参数值?
- node.js - 如何在使用 Node.js 进行异步调用后执行响应
- node.js - 错误:由于资源问题,在发送标头后无法设置标头。?
- c# - SignalR Hub 没有从客户端连接,甚至没有显示任何错误
- amazon-web-services - 如何使 AWS Lex 机器人在意图实现后提示跟进(使用 Lambda)?
- adobe - 自动热键脚本结合而不是替换鼠标滚轮原始功能
- camera - 如何使用 EmguCV c# 将 IP 摄像机快照保存在 Content 文件夹中
- mysql - SQL 查询以在一次扫描中获取结果,而不使用分析函数
- javascript - 如何在分离的 Javascript 中处理会话数据?