Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Flatter SingleChildScrollView在堆栈内不工作_Flutter_Flutter Layout - Fatal编程技术网

Flutter Flatter SingleChildScrollView在堆栈内不工作

Flutter Flatter SingleChildScrollView在堆栈内不工作,flutter,flutter-layout,Flutter,Flutter Layout,因此,我尝试制作一个带有滚动的堆栈的屏幕,我使用AlignPosited包来对齐堆栈中的定位部件我尝试使用扩展部件布局生成器,但我不知道如何使其动态 下面有很多城市名称,根据集装箱的高度,屏幕只能滚动到1-2个城市名称。这是我当前的代码,每当我设置容器的恒定高度时,UI不会抛出错误,但屏幕不能完全滚动 return SafeArea( child: Scaffold( body: SingleChildScrollView( child: Container(

因此,我尝试制作一个带有滚动的堆栈的屏幕,我使用AlignPosited包来对齐堆栈中的定位部件我尝试使用扩展部件布局生成器,但我不知道如何使其动态

下面有很多城市名称,根据集装箱的高度,屏幕只能滚动到1-2个城市名称。这是我当前的代码,每当我设置容器的恒定高度时,UI不会抛出错误,但屏幕不能完全滚动

return SafeArea(
  child: Scaffold(
      body: SingleChildScrollView(
        child: Container(
          height: MediaQuery.of(context).size.height,
          child: Stack(
            children: <Widget>[
              Positioned(
                top: 0,
                child: TopArc(), // The blue background circle
              ),
              AlignPositioned(
                dy: 40,
                alignment: Alignment.topCenter,
                child: Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 16, vertical: 4),
                  child: AutoSizeText(
                    "Choose Your Location",
                    stepGranularity: 1,
                    maxLines: 1,
                    style: TextStyle(
                      fontSize: 38,
                      color: Colors.white,
                      // This is the maximum value then the AutoSizeText widget will shrink it until it can fit a single line.
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
              AlignPositioned(
                dy: 90,
                alignment: Alignment.topCenter,
                child: StreamBuilder<QuerySnapshot>(
                  stream: Firestore.instance
                      .collection('locations')
                      .snapshots(),
                  builder: (context, snapshot) {
                    if (snapshot.hasError) {
                      return CircularProgressIndicator();
                    }
                    if (!snapshot.hasData) {
                      return CircularProgressIndicator();
                    }
                    return ContentTile(
                      child: ListView.builder(
                        physics: NeverScrollableScrollPhysics(),
                        shrinkWrap: true,
                        itemCount: snapshot.data.documents.length,
                        itemBuilder: (ctx, int i) {
                          final document = snapshot.data.documents[i];

                          return LocationExpansionTile(
                              document.documentID, document["cityName"]);
                        },
                      ),
                    );
                  },
                ),
              ),
            ],
          ),
        ),
      )),
);
将ListView.builder替换为Column小部件,并删除所有AlignedPosited,如果可能,请使用Posited。移除堆栈的父容器并添加具有高度值的容器。它将帮助堆栈计算其大小。您必须从物品列表中获取最终尺寸。这就是我可以让你的代码按你想要的方式运行的方法

var _itemsView = GlobalKey();

double _stackHeight;

@override
void initState() {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    RenderBox stackRB =
        _itemsView.currentContext.findRenderObject() as RenderBox;
    setState(() {
      _stackHeight = stackRB.size.height;
    });
  });
  super.initState();
}

@override
Widget build(BuildContext context) {
  return SafeArea(
    child: Scaffold(
        body: SingleChildScrollView(
      child: Stack(
        children: <Widget>[
          Positioned(
            ...
          ),
          Positioned(
            ...
          ),
          Positioned(
            key: _itemsView,
            top: 90,
            child: Column(
              children: _data.map((i) {
                  final document = snapshot.data.documents[i];
                  return LocationExpansionTile(
                      item.documentID, item["cityName"]);
                }),
            ),
          ),
          Container(
            height: _stackHeight + 90,
          )
        ],
      ),
    )),
  );
}

我处理的问题几乎是相同的,如果你的SingleChildScrollView在一个定位的小部件中,你必须精确定位的顶部和底部,在我的情况下,我没有预测底部,所以我无法向下滚动

我无法构建屏幕,因为它抛出的方法“FindEnderObject”被调用为null。这error@ahmetakil您是否将_itemsView设置为正确的小部件?从对齐小部件更改为定位小部件。这对我有用。非常感谢。