谢谢吉姆,
您的回复让我找到了解决方案。但是,要使 Positioned 小部件工作,封闭的 Stack 必须仅包含 StatelessWidgets 或 StatefulWidgets 而不是像我最初使用的 ClipRRect 那样的 RenderObjectWidgets。我必须将图像包含在我称为 StackImage 的 StatelessWidget 中。
class PicTab extends StatelessWidget {
const PicTab({Key key, @required this.name, @required this.state})
: super(key: key);
final String name;
final SubmodulesState state;
@override
Widget build(BuildContext context) {
//
String image;
if (name == null || name.isEmpty) {
image = 'river_bend';
} else {
image = name.trim();
}
final stackImage = StackImage(name: 'assets/images/$image.jpg');
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 3),
child: Stack(
children: [
stackImage,
Positioned(
bottom: 0,
child: Container(
width: stackImage.width,
height: stackImage.height * 0.3,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(32),
color: Colors.white.withOpacity(0.5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(''),
]),
),
),
],
),
);
}
}
class StackImage extends StatelessWidget {
const StackImage({
Key key,
@required this.name,
this.width = 250,
this.height = 250,
}) : super(key: key);
final String name;
final double width;
final double height;
@override
Container build(BuildContext context) => Container(
width: width,
height: height,
child: ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.asset(
name,
fit: BoxFit.cover,
),
),
);
}