【发布时间】:2021-02-19 15:29:58
【问题描述】:
如何使 Stack 元素在从纵向旋转到横向时不发生变化? 我已经添加了图像和我的堆栈代码,不知道我在做什么错任何人都可以帮助我。
我已经尝试根据方向更改设计但没有运气我认为在搜索时必须有一种简单的方法我遇到这个“Positioned.fromRect()”但不知道如何使用它或它的作用.
提前谢谢你。
displayHeight(context) 和 displayWidth(context) 从上述函数中获取值。
double displayHeight(BuildContext context) {
debugPrint('Height = ' +
(MediaQuery.of(context).size.height - kToolbarHeight).toString());
return displaySize(context).height - kToolbarHeight;
}
double displayWidth(BuildContext context) {
debugPrint('Width = ' + MediaQuery.of(context).size.width.toString());
return displaySize(context).width;
}
Stack(
alignment: AlignmentDirectional.topCenter,
children: <Widget>[
Positioned(
child: Image.asset(
'images/header.png',
height: displayHeight(context) * 0.38,
width: double.infinity,
fit: BoxFit.cover,
),
),
Positioned(
top: displayHeight(context) * 0.02,
width: displayWidth(context),
child: Container(
child: Text(
"Want to promote good health? you are in a right place.",
textAlign: TextAlign.center,
softWrap: true,
style: TextStyle(
fontSize: displayWidth(context) * 0.05,
fontWeight: FontWeight.bold,
color: Colors.orange.withOpacity(0.6)),
),
),
),
Positioned(
top: displayHeight(context) * 0.04,
child: Container(
child: Image.asset(
'images/run2.png',
height: displayHeight(context) * 0.37,
width: displayWidth(context) * 0.95,
),
),
),
//top Sponsor button code parts
Positioned(
top: displayHeight(context) * 0.2,
left: displayWidth(context) * 0.1,
child: new RaisedButton(
padding: const EdgeInsets.all(10),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
child: new Text(
'Sponsor A Run',
style: TextStyle(
fontSize: displayWidth(context) * 0.06,
fontWeight: FontWeight.bold,
color: Colors.white),
),
color: isButtonPressed
? Colors.orange
: Colors.orange.withOpacity(0.4),
onPressed: () {
setState(() {
isButtonPressed = !isButtonPressed;
});
},
),
),
Positioned(
top: displayHeight(context) * 0.08,
right: displayWidth(context) * 0.03,
child: Image.asset(
'images/pot1.png',
height: displayHeight(context) * 0.3,
width: displayWidth(context) * 0.3,
),
),
],
),
【问题讨论】:
标签: flutter stack orientation positioning