refactor: use ListView for stream grid

This commit is contained in:
2025-05-13 10:18:39 +01:00
parent e6531bff7c
commit 994b40dda9

View File

@ -21,45 +21,71 @@ class StreamGrid extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final streams = events final streams =
.map((e) => StreamEvent(e)) events
.sortedBy((a) => a.info.starts ?? a.event.createdAt) .map((e) => StreamEvent(e))
.reversed; .sortedBy((a) => a.info.starts ?? a.event.createdAt)
.reversed;
final live = streams.where((s) => s.info.status == StreamStatus.live); final live = streams.where((s) => s.info.status == StreamStatus.live);
final ended = streams.where((s) => s.info.status == StreamStatus.ended); final ended = streams.where((s) => s.info.status == StreamStatus.ended);
final planned = streams.where((s) => s.info.status == StreamStatus.planned); final planned = streams.where((s) => s.info.status == StreamStatus.planned);
return Column( return Column(
spacing: 16, spacing: 16,
children: [ children: [
if (showLive && live.isNotEmpty) _streamGroup("Live", live), if (showLive && live.isNotEmpty) _streamGroup(context, "Live", live),
if (showPlanned && planned.isNotEmpty) _streamGroup("Planned", planned), if (showPlanned && planned.isNotEmpty)
if (showEnded && ended.isNotEmpty) _streamGroup("Ended", ended), _streamGroup(context, "Planned", planned),
if (showEnded && ended.isNotEmpty)
_streamGroup(context, "Ended", ended),
], ],
); );
} }
Widget _streamGroup(String title, Iterable<StreamEvent> events) { Widget _streamTitle(String title) {
return Row(
spacing: 16,
children: [
Text(
title,
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500),
),
Expanded(
child: Container(
height: 1,
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: LAYER_2)),
),
),
),
],
);
}
Widget _streamGroup(
BuildContext context,
String title,
Iterable<StreamEvent> events,
) {
final eventList = events.toList();
// profide fixed item size for performance
final q = MediaQuery.of(context);
return Column( return Column(
spacing: 16, spacing: 16,
children: [ children: [
Row( _streamTitle(title),
spacing: 16, ListView.builder(
children: [ itemCount: eventList.length,
Text( primary: false,
title, shrinkWrap: true,
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500), itemBuilder: (ctx, idx) {
), final stream = eventList[idx];
Expanded( return Padding(
child: Container( padding: EdgeInsets.symmetric(vertical: 8),
height: 1, child: StreamTileWidget(stream),
decoration: BoxDecoration( );
border: Border(bottom: BorderSide(color: LAYER_2)), },
),
),
),
],
), ),
...events.map((e) => StreamTileWidget(e)),
], ],
); );
} }