flutter - Flutter sticky_headers - 有没有办法组合相似的标题并在它下面有多个项目?
问题描述
我目前正在使用当前代码:
class Listing extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (kDebugMode) print ('Building Listing');
return Scaffold(
backgroundColor: Colors.blueGrey[900],
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
for (Booking booking in Provider.of<CP>(context).bookings.values)
ListTileTheme(
// key: Key(booking.orderUID),
contentPadding: EdgeInsets.zero,
// minVerticalPadding: -1.0,
dense: true,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20.0, vertical: 5.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 3,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: StickyHeader(
header: Container(
height: 50.0,
color: Colors.black,
padding: EdgeInsets.symmetric(horizontal: 16.0),
alignment: Alignment.centerLeft,
child: Text(DateFormat('E d MMM').format(DateTime.fromMillisecondsSinceEpoch(booking.dateUnix)),
style: headerStyle,
),
),
content: BookingTileView(booking: booking))),
)
],
),
),
),
);
}
}
目前,每个项目都有自己的标题。最好有一个类似项目的标题,但我不知道该怎么做?任何有关示例代码的帮助将不胜感激...谢谢
解决方案
尝试使用flutter_sticky_header代替:
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
import '../common.dart';
class ListExample extends StatelessWidget {
const ListExample({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AppScaffold(
title: 'List Example',
slivers: [//<-----Group of Headers
_StickyHeaderList(index: 0),
_StickyHeaderList(index: 1),
_StickyHeaderList(index: 2),
_StickyHeaderList(index: 3),
],
);
}
}
class _StickyHeaderList extends StatelessWidget {
const _StickyHeaderList({
Key? key,
this.index,
}) : super(key: key);
final int? index;
@override
Widget build(BuildContext context) {
return SliverStickyHeader(//<-----Header
header: Header(index: index),
sliver: SliverList(//<-----Group items
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 6,
),
),
);
}
}
推荐阅读
- c# - 使用列表保存多个复选框的状态
- python - 使用已排序按字母数字值对列进行排序
- python - 将两个具有外键关系的模型数据传递给一个 html 模板
- python - 提交按钮没有点击 selenium python?
- arel - 如何将 `matches()` 与数据库函数一起使用?
- git - 如何推送一次并取消跟踪?
- google-drive-api - 如何确定更改是通过 API 发生的还是由人为发生的?
- entity-framework-core - EF Core 并以最佳方式加载相关数据
- python - 为什么此代码在一种情况下有效,而在另一种情况下无效?
- angular - Angular Material MatSort 和sortingDataAccessor 如何协同工作?