【发布时间】:2020-03-09 19:04:54
【问题描述】:
所以我正在尝试制作一个具有滚动堆栈的屏幕,并且我正在使用 AlignPositioned 包来对齐堆栈中的定位小部件我尝试使用扩展小部件 LayoutBuilders 我只是不知道如何制作它动态 (https://pub.dev/packages/align_positioned)
下面有很多城市名称,根据容器的高度,屏幕只能滚动到其中的1-2个。这是我当前的代码,每当我为 Container 设置恒定高度时,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"]);
},
),
);
},
),
),
],
),
),
)),
);
【问题讨论】: