Dart 颤振位置固定当量

Dart 颤振位置固定当量,dart,flutter,Dart,Flutter,是否可以在屏幕中修复一个对象,该对象无论滚动都保持不变 类似于CSS定位的东西已修复。您完全可以使用小部件定位小部件的子部件 下面的最小示例通过将子对象放置在堆栈子对象的ListView之后的定位小部件中,将红色框放置在列表视图上方 列出待办事项=[…]; 返回新堆栈( 儿童:[ 新列表视图( 儿童:待办事项 .map((todo)=>new ListTile(标题:new Text(todo))) .toList(), ), 新定位( 左:30.0, 排名:30.0, 子容器:新容器( 宽度:

是否可以在屏幕中修复一个对象,该对象无论滚动都保持不变


类似于CSS定位的东西已修复。

您完全可以使用小部件定位小部件的子部件

下面的最小示例通过将子对象放置在堆栈子对象的ListView之后的定位小部件中,将红色框放置在列表视图上方

列出待办事项=[…];
返回新堆栈(
儿童:[
新列表视图(
儿童:待办事项
.map((todo)=>new ListTile(标题:new Text(todo)))
.toList(),
),
新定位(
左:30.0,
排名:30.0,
子容器:新容器(
宽度:100.0,
身高:80.0,
装饰:新盒子装饰(颜色:Colors.red),
孩子:新文本(“你好”),
)
),
],
);
在这里,它位于
支架的内部。如果您添加更多的项目,您会发现列表滚动而不移动红色框

您可以在带有widget的widget中使用widget,并使用%距离,如下面的代码所示

@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size; //get the screen size

List<String> todos = [...];

//the below if to get the aspect ratio of the screen i am using the app only in landscape
//if you need to use it in portrait you should add the sizes below
if((size.width / size.height) > 1.76){
  aspect = 16 / 9;
}else if((size.width / size.height) < 1.77 && (size.width / size.height) >= 1.6){
  aspect = 16 / 10;
}else{
  aspect = 4 /3;
}

return new Scaffold(
  body: new Center(
      //layoutBuilder i can use the constraints to get the width and height of the screen
      child: new LayoutBuilder(builder: (context, constraints) {
        return new AspectRatio(
          aspectRatio: aspect,
          child: new Column(
            children: <Widget>[
               new ListView(
                    children: todos
                    .map((todo) => new ListTile(title: new Text(todo)))
                    .toList(),
               ),
               new Positioned(
                    //constraints.biggest.height to get the height 
                    // * .05 to put the position top: 5%
                    top: constraints.biggest.height * .05,
                    left: constraints.biggest.width * .30,
                    child: new Container(
                              width: 100.0,
                              height: 80.0,
                              decoration: new BoxDecoration(color: Colors.red),
                              child: new Text('hello'),
                          ),
                    ),
            ],
          ),
        ),
      }),
    ),
  );
}
}
@覆盖
小部件构建(构建上下文){
Size Size=MediaQuery.of(context).Size;//获取屏幕大小
列出待办事项=[…];
//如果要获得屏幕的纵横比,我只在横向中使用应用程序,请参见下面的示例
//如果您需要在肖像中使用它,您应该添加以下尺寸
如果((尺寸宽度/尺寸高度)>1.76){
纵横比=16/9;
}如果((size.width/size.height)<1.77&&(size.width/size.height)>=1.6){
纵横比=16/10;
}否则{
纵横比=4/3;
}
归还新脚手架(
正文:新中心(
//layoutBuilder我可以使用约束来获得屏幕的宽度和高度
子级:新布局生成器(生成器:(上下文,约束){
返回新AspectRatio(
方面:方面,
子:新列(
儿童:[
新列表视图(
儿童:待办事项
.map((todo)=>new ListTile(标题:new Text(todo)))
.toList(),
),
新定位(
//约束.max.height以获取高度
//*.05排名靠前:5%
顶部:constraints.max.height*.05,
左:constraints.max.width*.30,
子容器:新容器(
宽度:100.0,
身高:80.0,
装饰:新盒子装饰(颜色:Colors.red),
孩子:新文本(“你好”),
),
),
],
),
),
}),
),
);
}
}

希望它能帮助您……

我正在使用Stack and Posited,但当我在定位的子隐藏中添加left或right或bottom或top属性时。我正在使用Stack and Posited,但当我在定位的子隐藏中添加left或right或bottom或top属性时。@AliAzad Posited需要是堆栈的最后一个子级