在此示例中,我想创建一个由 ItemData 参数列表填充的 ListViewTiles 的 ListView。
我想将标题图像放置为同一 ListView 的顶部小部件。
Image 必须与 ListTiles 的其余部分一起滚动。
Widget _buildListViewWithHeader(BuildContext context, Image banner, List<ItemData> items) {
return ListView.builder(
itemBuilder: (context, index) {
return ListTile(
leading: items[index].leading,
title: items[index].title,
trailing: items[index].trailing,
);
},
);
}
Run Code Online (Sandbox Code Playgroud)
如何将图像放置在此ListView 的顶部?
是否有一种通用方法将小部件列表传递给 listView 并将它们放置在项目生成器生成的小部件之前?
我想改变我的项目,它比列表视图本身更大。(集中导航的意图)
我的列表:
Container(
height: 100,
child: ListView.builder(
itemBuilder: (context, index) => HomeItem(title: '$index'),
scrollDirection: Axis.horizontal,
),
),
Run Code Online (Sandbox Code Playgroud)
我的物品:
class HomeItem extends StatelessWidget {
final String title;
final bool expand;
const HomeItem({
@required this.title,
this.expand = false,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: ThemeDimens.padding8),
child: Transform.scale(
scale: expand ? 1.5 : 1,
child: AnimatedContainer(
width: 50,
height: 100,
color: expand ? ThemeColors.accent : ThemeColors.primary,
duration: ThemeDurations.shortAnimationDuration(),
child: Center(
child: Text(title),
),
),
),
);
}
} …Run Code Online (Sandbox Code Playgroud) 如果我从列表顶部添加多个元素,列表视图的滚动位置会发生变化。当我们在列表底部插入新元素时,它对于插入操作运行良好。
用例是我的应用程序中有一个聊天模块,我必须在其中实现两侧分页(向上和向下)。如果用户向上滚动,则正常分页流程,项目会添加到列表底部,因此工作正常。但是,如果用户向下滚动,则列表顶部添加的新项目和滚动位置会发生变化。
我已经在所有地方进行了搜索并尝试了所有解决方案,但没有找到任何合适的解决方案,而且许多人也面临着同样的问题。
我附上此问题的一个 dartpad 链接:open dartpad
重现步骤:
运行应用程序,滚动到列表末尾
现在点击添加图标,它将在列表顶部添加 30 个项目,您会注意到滚动位置将在之后发生变化
在此示例中,我使用 setState 但即使在使用任何状态管理解决方案后也会发生同样的事情。
如果我从列表顶部添加元素,我希望不会更改滚动位置
我正在开发一个项目,在其中生成订单列表。每当我尝试从列表中删除一个项目时。它抛出了异常RangeError (index): Invalid value: Only valid value is 0: 1。但是,它会同时删除该项目。如果存在范围问题,为什么要删除该项目?或者这个错误是什么时候产生的?另一件事是如何在特定小部件中应用 try/catch?
这是代码:
class OrderList extends StatefulWidget {
@override
_OrderListState createState() => _OrderListState();
}
class _OrderListState extends State<OrderList> {
CartList cart = CartList.instance;
final GlobalKey<AnimatedListState> _key = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
elevation: 0.0,
title: Text('Orders'),
centerTitle: true,
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Badge(
child: Icon(Icons.shopping_cart, color: Colors.white, size: 40),
badgeContent: Text(
cart.listLength(),
style: TextStyle(color: Colors.white),
),
badgeColor: Colors.amber,
toAnimate: …Run Code Online (Sandbox Code Playgroud) 为了提高性能,我在 Listview 中使用了cacheExtent: double.infinity。但在ios中会弹出错误。如何修复此错误以及为什么会出现此错误?
代码 :
ListView.separated(
cacheExtent: double.infinity,
padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
itemCount: 200,
itemBuilder: (_, index) {
return _buildItem();
},
separatorBuilder: (context, index) {
return Divider(
color: AppColors.app_list_divider,
);
},
)
Run Code Online (Sandbox Code Playgroud)
错误 :
扑动:[2022-02-16 16:39:40.239153 | 捕手| 细]错误:''package:flutter/src/semantics/semantics.dart':断言失败:第1592行第12行:'value.isFinite':SemanticsNode#60(Rect.fromLTRB(0.0,0.0,0.0,0.0),标签:[RenderViewport.twoPane],不可见)(为空)尝试设置一个非有限矩形。由于 3000 毫秒内发生重复而被跳过。
我有一个容器,我试图打印出列表中的项目,减去列表中的最后一个项目。我正在使用 list.generate:
child: Container(
width: double.infinity,
color: Colors.white,
child: ListView(
padding: const EdgeInsets.only(top: 10.0),
children: List.generate(
Provider.of<WeekList>(context).listOfWeeks.toList().length -
1,
(index) => ListTileCustom(
index: index,
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我的问题是,当它打印出我的自定义ListTileCustom小部件时,添加到列表中的每个新项目都会添加到视图的底部而不是顶部。
上图中的顺序应该是:
当我通过按下按钮添加新项目时,它们应该添加到顶部而不是底部。
我尝试添加reverse: true,这得到了正确的顺序,但将所有内容移动到底部并在它们上面添加了大量的空白...也不确定滚动在那时是否会在正确的方向上工作。
ListViewflutter 上有一个属性我仍然不明白: prototypeItem。
https://api.flutter.dev/flutter/widgets/ListView/prototypeItem.html
SizedBox?我想让屏幕像顶部一样显示谷歌地图和一个过滤表单,然后最后显示垂直列表视图。我有很多尝试,但地图不是垂直滚动,而是采用列表视图的滚动。
以及如何在地图中添加缩放加和缩放减按钮
我的小部件树就像.. mapView 是 GoogleMap 小部件。
return ListView(
children: <Widget>[
SizedBox(height: mapHeight, child: MapView()),
ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: <Widget>[
getForm(context),
getWorkerList(context)
],
) ,
],
);
Run Code Online (Sandbox Code Playgroud)
另一个尝试如下但没有得到正确的输出
return ListView(
children: <Widget>[
SizedBox(
height: 300,
child: ListView(
//i want to disable listview scrolling when scroll on map
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
Container(
height: 300,
child: MapView1()),
],
)),
getForm(context),
getWorkerList(context)
],
);
Run Code Online (Sandbox Code Playgroud)
地图视图代码
@override
Widget build(BuildContext context) {
return GoogleMap(
mapToolbarEnabled: true,
myLocationEnabled: true,
zoomGesturesEnabled: true,
scrollGesturesEnabled: …Run Code Online (Sandbox Code Playgroud) 我是这个框架的新手,并且无法显示 ListViewBuilder 项目。我在控制台中收到此错误
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 捕获异常通过渲染库 \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\ x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\ xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\ x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\ x90\nRenderBox 未布局:RenderRepaintBoundary#f28ee relayoutBoundary=up14 NEEDS-PAINT\n'package:flutter/src/rendering/box.dart':\n断言失败:第 1785 行 pos 12:'hasSize'
\nclass _ViewCartState extends State<ViewCart> {\n\n List<dynamic> cartData;\n\n @override\n void initState() {\n super.initState();\n APIService apiService = new APIService();\n apiService.apiCall().then((value) async {\n setState(() {\n cartData = value.data.result.cartData;\n print(cartData);\n });\n });\n }\n\n @override\n Widget build(BuildContext context) {\n loadData();\n var veg;\n return Scaffold(\n appBar: AppBar(\n iconTheme: IconThemeData(\n color: kHintColor, //change your color here\n ),\n title: Text("Cart Page", style: Theme.of(context).textTheme.bodyText1),\n ),\n body: Stack(\n children: <Widget>[\n SingleChildScrollView(\n …Run Code Online (Sandbox Code Playgroud)