gpt4 book ai didi

Flutter - 可滚动容器

转载 作者:IT王子 更新时间:2023-10-29 06:50:05 24 4
gpt4 key购买 nike

我有一个具有图像(地点) ListView 的应用程序,然后在点击时返回一个新页面,显示有关该地点的某些详细信息。我关心的是详细信息页面,我的布局是我在顶部有一个图像,在它下面有一些文本和一个扩展的 ListView 。我想要的是我可以滚动浏览整个页面。我想到的是只有展开的 ListView 是可滚动的。

详情页代码如下:

 import 'package:flutter/material.dart';
import 'package:craglist/cragspot.dart';

class CragDetailsScreen extends StatelessWidget {
final CragLocation loc;

final _placeTitleStyle = const TextStyle(
fontSize: 40.0, fontWeight: FontWeight.bold, color: Colors.black);

CragDetailsScreen(this.loc);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Details"),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
height: 300.0,
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: new AssetImage(loc.placeImage),
),
),
),
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(
loc.name,
style: _placeTitleStyle,
),
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
loc.desc,
),
),
new Padding(
padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0),
child: new Divider(
height: 15.0,
),
),
new Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: new Text(
"Crags",
style: _placeTitleStyle,
),
),
new Expanded(child: _buildCragList()),
],
),
);
}

Widget _buildCragList() {
return new ListView.builder(
itemCount: loc.crag.length,
itemBuilder: (context, i) {
return _buildRow(loc.crag[i]);
});
}

Widget _buildRow(Crag crag) {
List<Widget> widcrag = [];

crag.routes.forEach((f) {
widcrag.add(
new ListTile(
dense: true,
title: new Text(f.name),
trailing: new Text(f.grade),
),
);
});

return new ExpansionTile(
title: new Text(crag.name),
children: widcrag,
);
}
}

另外 - 是否有可能在我滚动图像时调整大小?在屏幕上为展开的 ListView 提供更多空间。

最佳答案

您可以将所有内容包装在 ListView.builder 中,然后添加一个 if 语句以确定它是否在第一个小部件上工作。如果它位于第一个小部件,它会添加所有应该位于顶部的内容。如果不是,它会添加索引为 +1 的普通列表项。像这样:

new ListView.builder(
itemCount: loc.crag.length,
itemBuilder: (context, index) {
int i = index;
if (i == 0) {
return new Column(children: <Widget>[
new Container(
height: 300.0,
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: new AssetImage(loc.placeImage),
),
),
),
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(
loc.name,
style: _placeTitleStyle,
),
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
loc.desc,
),
),
new Padding(
padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0),
child: new Divider(
height: 15.0,
),
),
new Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: new Text(
"Crags",
style: _placeTitleStyle,
),
),
],);
} else {
_buildRow(loc.crag[i+1]);
}
}
)

关于Flutter - 可滚动容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50965005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com