Vij*_*jay 8 dart flutter flutter-layout
我正在使用 Flutter 进行我的应用程序开发。我想将海报图像视图叠加在背景图像之上,就像下面的屏幕截图一样。
下面的代码片段做到了这一点,但它要求我还根据海报的位置和背景图像的位置定位所有其他小部件,包括电影标题、发布日期等,这在多个设备和方向上是不可靠的。是否有解决此问题的示例或建议?
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new PlatformAdaptiveAppBar(
title: new Text(widget.movie.title),
),
body: new Container(
constraints: new BoxConstraints.expand(),
child: new Stack(
children: <Widget>[
new Container(
child: new Image(
image: new AdvancedNetworkImage(
movieGridUtil.getUrlFromPath(widget.movie.backdrop_path,
MovieGridImageTypes.BACKDROP),
useMemoryCache: false,
useDiskCache: true)),
constraints: new BoxConstraints.expand(height: 250.0),
),
new Positioned(
left: 12.0,
top: 220.0,
child: new Image(
width: 100.0,
height: 150.0,
image: new AdvancedNetworkImage(
movieGridUtil.getUrlFromPath(widget.movie.poster_path,
MovieGridImageTypes.POSTER),
useMemoryCache: false,
useDiskCache: true),
)),
],
)),
);
}
Run Code Online (Sandbox Code Playgroud)
创建堆栈
然后在 Stack 中添加 Column 并在没有海报的情况下进行完整布局。然后作为 Stack 的第二个孩子,添加这个组合:
new Stack(
children: [
new Column(
children: _layout()
new Positioned(
top:200,
left:50,
child: _child // or optionaly wrap the child in FractionalTranslation
)]
)
)
Run Code Online (Sandbox Code Playgroud)
Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 200.0,
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0, top:160.0),
child: Container(
color: Colors.pink,
height: 150.0,
width: 110.0,
),
)
],
),
Run Code Online (Sandbox Code Playgroud)
通过创建Stack,您可以添加多个Container,最后添加的容器将位于顶部。
Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 200.0,
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0, top:160.0),
child: Container(
color: Colors.pink,
height: 150.0,
width: 110.0,
),
)
],
),
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11989 次 |
最近记录: |