飞镖 – 颤振位置固定等效

前端之家收集整理的这篇文章主要介绍了飞镖 – 颤振位置固定等效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论滚动如何,是否可以在屏幕中修复保持固定的对象?

类似于CSS位置固定的东西.

解决方法

您可以使用 Positioned小部件绝对定位 Stack小部件的子级.

下面的最小示例将红色框放在列表视图上方,方法是将子项放在Stack的子项中ListView之后的Positioned小部件中.

List<String> todos = [...];
return new Stack(
  children: <Widget>[
    new ListView(
     children: todos
       .map((todo) => new ListTile(title: new Text(todo)))
       .toList(),),new Positioned(
       left: 30.0,top: 30.0,child: new Container(
         width: 100.0,height: 80.0,decoration: new BoxDecoration(color: Colors.red),child: new Text('hello'),)
      ),],);

而这里是一个脚手架的身体.如果您添加更多项目,您会发现列表滚动而不移动红色框.

an absolutely positioned example

猜你在找的Flutter相关文章