Skip to content

Commit 6a0db14

Browse files
committed
fixed locmax issue by moving news card to ItemCard widget
1 parent 64603a9 commit 6a0db14

2 files changed

Lines changed: 154 additions & 99 deletions

File tree

lib/news/list_news.dart

Lines changed: 9 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ import 'package:communitypod/constants/ui.dart';
3131
import 'package:communitypod/models/news.dart';
3232
import 'package:communitypod/models/selected_news.dart';
3333
import 'package:communitypod/news/list_news_screen.dart';
34-
import 'package:communitypod/news/non_readable_news_post.dart';
35-
import 'package:communitypod/news/view_news.dart';
36-
import 'package:communitypod/widgets/highlight_image.dart';
37-
import 'package:communitypod/widgets/item_subtitle.dart';
38-
import 'package:communitypod/widgets/item_title.dart';
39-
import 'package:communitypod/widgets/item_trailing_buttons.dart';
34+
import 'package:communitypod/widgets/item_card.dart';
4035
import 'package:communitypod/widgets/list_del_button.dart';
4136

4237
/// A [stateful] widget to list news accessible to the
@@ -559,99 +554,14 @@ class _ListNewsState extends State<ListNews> {
559554
controller: _scrollController,
560555
padding: const EdgeInsets.all(10),
561556
itemCount: _foundNews.length,
562-
itemBuilder: (context, index) => Card(
563-
child: Column(
564-
crossAxisAlignment: CrossAxisAlignment.stretch,
565-
children: [
566-
HighlightImage(
567-
imageUrl: _foundNews[index]
568-
.permissionList
569-
.contains('read')
570-
? _foundNews[index].content?.highlightImageUrl
571-
: null,
572-
),
573-
Center(
574-
child: Container(
575-
// Show color decoration when selected
576-
decoration: _foundNews[index].isSelected
577-
? BoxDecoration(
578-
color: theme.colorScheme.onInverseSurface,
579-
borderRadius: const BorderRadius.all(
580-
Radius.circular(5),
581-
),
582-
)
583-
: const BoxDecoration(
584-
borderRadius:
585-
BorderRadius.all(Radius.circular(5)),
586-
),
587-
child: ListTile(
588-
// Select and count selected news files, including whether
589-
// an externally owned news files are selected
590-
leading: SizedBox(
591-
width: NewsIconSize.width,
592-
child: Center(
593-
child: Ink(
594-
decoration: buttonShapeList,
595-
child: IconButton(
596-
icon: _foundNews[index].isSelected
597-
? const Icon(Icons.done)
598-
: const Icon(Icons.edit_document),
599-
onPressed: () {
600-
updateSelectionMode(
601-
_isSelectionMode,
602-
index,
603-
);
604-
updateSelected(index);
605-
},
606-
),
607-
),
608-
),
609-
),
610-
// News post info
611-
title: ItemTitle(
612-
item: _foundNews[index],
613-
isNarrow: isNarrow,
614-
),
615-
// News post item subtitle
616-
subtitle: ItemSubtitle(
617-
item: _foundNews[index],
618-
isNarrow: isNarrow,
619-
),
620-
// Define width to avoid consuming full width
621-
trailing: SizedBox(
622-
height: 60,
623-
width: 120,
624-
child: ItemTrailingButtons(
625-
item: _foundNews[index],
626-
scaffoldController: _scaffoldController,
627-
),
628-
),
629-
630-
onTap: () {
631-
// Open news file object if read in permissions
632-
String access =
633-
_foundNews[index].permissionList;
634-
if (access.contains('read')) {
635-
_scaffoldController.navigateToSubpage(
636-
ViewNews(
637-
newsPost: _foundNews[index],
638-
scaffoldController: _scaffoldController,
639-
),
640-
);
641-
} else {
642-
_scaffoldController.navigateToSubpage(
643-
NonReadableNewsPost(
644-
newsPost: _foundNews[index],
645-
scaffoldController: _scaffoldController,
646-
),
647-
);
648-
}
649-
},
650-
),
651-
),
652-
),
653-
],
654-
),
557+
itemBuilder: (context, index) => ItemCard(
558+
item: _foundNews[index],
559+
isNarrow: isNarrow,
560+
scaffoldController: _scaffoldController,
561+
onSelectPressed: () {
562+
updateSelectionMode(_isSelectionMode, index);
563+
updateSelected(index);
564+
},
655565
),
656566
),
657567
),

lib/widgets/item_card.dart

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/// A stateful widget to display a news post card.
2+
///
3+
/// Copyright (C) 2026 Software Innovation Institute, Australian National University
4+
///
5+
/// License: GNU General Public License, Version 3 (the "License")
6+
/// https://opensource.org/license/gpl-3-0
7+
//
8+
// This program is free software: you can redistribute it and/or modify it under
9+
// the terms of the GNU General Public License as published by the Free Software
10+
// Foundation, either version 3 of the License, or (at your option) any later
11+
// version.
12+
//
13+
// This program is distributed in the hope that it will be useful, but WITHOUT
14+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16+
// details.
17+
//
18+
// You should have received a copy of the GNU General Public License along with
19+
// this program. If not, see <https://opensource.org/license/gpl-3-0>.
20+
///
21+
/// Authors: Jess Moore
22+
23+
library;
24+
25+
import 'package:flutter/material.dart';
26+
27+
import 'package:solidui/solidui.dart';
28+
29+
import 'package:communitypod/constants/app.dart';
30+
import 'package:communitypod/models/news.dart';
31+
import 'package:communitypod/news/non_readable_news_post.dart';
32+
import 'package:communitypod/news/view_news.dart';
33+
import 'package:communitypod/widgets/highlight_image.dart';
34+
import 'package:communitypod/widgets/item_subtitle.dart';
35+
import 'package:communitypod/widgets/item_title.dart';
36+
import 'package:communitypod/widgets/item_trailing_buttons.dart';
37+
38+
/// A [stateful] widget to display a news post card.
39+
///
40+
/// Arguments:
41+
/// - [item] - The news post to display.
42+
/// - [isNarrow] - Whether the window is narrower than the narrow threshold.
43+
/// - [scaffoldController] - Controller for the Solid scaffold.
44+
/// - [onSelectPressed] - Callback invoked when the select button is pressed.
45+
46+
class ItemCard extends StatefulWidget {
47+
const ItemCard({
48+
super.key,
49+
required this.item,
50+
required this.isNarrow,
51+
required this.scaffoldController,
52+
required this.onSelectPressed,
53+
});
54+
55+
final News item;
56+
final bool isNarrow;
57+
final SolidScaffoldController scaffoldController;
58+
final VoidCallback onSelectPressed;
59+
60+
@override
61+
State<ItemCard> createState() => _ItemCardState();
62+
}
63+
64+
class _ItemCardState extends State<ItemCard> {
65+
@override
66+
Widget build(BuildContext context) {
67+
final theme = Theme.of(context);
68+
return Card(
69+
child: Column(
70+
crossAxisAlignment: CrossAxisAlignment.stretch,
71+
children: [
72+
HighlightImage(
73+
imageUrl: widget.item.permissionList.contains('read')
74+
? widget.item.content?.highlightImageUrl
75+
: null,
76+
),
77+
Center(
78+
child: Container(
79+
decoration: widget.item.isSelected
80+
? BoxDecoration(
81+
color: theme.colorScheme.onInverseSurface,
82+
borderRadius: const BorderRadius.all(
83+
Radius.circular(5),
84+
),
85+
)
86+
: const BoxDecoration(
87+
borderRadius: BorderRadius.all(Radius.circular(5)),
88+
),
89+
child: ListTile(
90+
leading: SizedBox(
91+
width: NewsIconSize.width,
92+
child: Center(
93+
child: Ink(
94+
decoration: buttonShapeList,
95+
child: IconButton(
96+
icon: widget.item.isSelected
97+
? const Icon(Icons.done)
98+
: const Icon(Icons.edit_document),
99+
onPressed: widget.onSelectPressed,
100+
),
101+
),
102+
),
103+
),
104+
title: ItemTitle(
105+
item: widget.item,
106+
isNarrow: widget.isNarrow,
107+
),
108+
subtitle: ItemSubtitle(
109+
item: widget.item,
110+
isNarrow: widget.isNarrow,
111+
),
112+
trailing: SizedBox(
113+
height: 60,
114+
width: 120,
115+
child: ItemTrailingButtons(
116+
item: widget.item,
117+
scaffoldController: widget.scaffoldController,
118+
),
119+
),
120+
onTap: () {
121+
final access = widget.item.permissionList;
122+
if (access.contains('read')) {
123+
widget.scaffoldController.navigateToSubpage(
124+
ViewNews(
125+
newsPost: widget.item,
126+
scaffoldController: widget.scaffoldController,
127+
),
128+
);
129+
} else {
130+
widget.scaffoldController.navigateToSubpage(
131+
NonReadableNewsPost(
132+
newsPost: widget.item,
133+
scaffoldController: widget.scaffoldController,
134+
),
135+
);
136+
}
137+
},
138+
),
139+
),
140+
),
141+
],
142+
),
143+
);
144+
}
145+
}

0 commit comments

Comments
 (0)