gpt4 book ai didi

flutter - 使用定位时如何添加BoxDecoration

转载 作者:行者123 更新时间:2023-12-03 03:22:31 25 4
gpt4 key购买 nike

我正在尝试在以下小部件中的某些文本上添加边框:

 Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
Positioned(
bottom: 0,
top: 70,
right: 50,
left: 50,
child: Text(
surprises[surpriseNumber]['Surprises'],
style: TextStyle(fontSize: 20, color: Colors.pink[700]),
textAlign: TextAlign.center,
),
),
],
),
);
}

但是我不知道该怎么做。根据我在网上找到的答案,我觉得这应该可行:
Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
Positioned(
bottom: 0,
top: 70,
right: 50,
left: 50,
child: Text(
surprises[surpriseNumber]['Surprises'],
style: TextStyle(fontSize: 20, color: Colors.pink[700]),
textAlign: TextAlign.center,
child: Container(
decoration: BoxDecoration(),
),
),
),
],
),
);
}


但它失败与 The named parameter 'child' isn't defined.
有人能指出我在哪里出问题了吗?

最佳答案

  @override
Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
Positioned(
bottom: 0,
top: 70,
right: 50,
left: 50,
child: Container(
decoration: BoxDecoration(
border: Border.all(),
),
child: Text(
'some text here',
style: TextStyle(fontSize: 20, color: Colors.pink[700]),
textAlign: TextAlign.center,
),
),
),
],
),
);
}

这应该工作!您只需要将文本小部件包装在容器内,并在BoxDecoration()中提供边框。您将容器放置为Text()小部件的子级,这是不可能的,因为Text()小部件没有名为child的参数。

关于flutter - 使用定位时如何添加BoxDecoration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61641549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com