Skip to content

Commit

Permalink
add tag chips
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Oct 29, 2021
1 parent 82fd1f0 commit d6ff822
Showing 1 changed file with 76 additions and 14 deletions.
90 changes: 76 additions & 14 deletions lib/widgets/notice_tile.dart
Expand Up @@ -104,8 +104,7 @@ class NoticeTile extends StatelessWidget {
? "${document?.date.split('-')[0]} ${DateFormat('MMM').format(DateTime(0, int.parse(document?.date.split('-')[1] ?? '0')))}"
: timeago
.format(DateTime.parse(
document?.createdAt.toString() ?? '0')
.add(const Duration(minutes: 40)))
document?.createdAt.toString() ?? '0'))
.replaceAll('about', '')
.replaceAll('hour', 'hr')
.replaceAll('minute', 'min')
Expand Down Expand Up @@ -222,7 +221,9 @@ class NoticeTile extends StatelessWidget {
border: Border(
bottom: BorderSide(color: Colors.grey.shade300, width: 0.5))),
child: ListTile(
isThreeLine: (document?.college ?? '').toUpperCase().trim() != "",
isThreeLine:
(document?.college ?? '').toUpperCase().trim().isNotEmpty ||
((document?.tags ?? []).isNotEmpty),
enableFeedback: true,
onLongPress: () {
logger.d("Long Press");
Expand Down Expand Up @@ -258,15 +259,54 @@ class NoticeTile extends StatelessWidget {
),
),
subtitle: (document?.college ?? '').toUpperCase().trim() == ""
? null
: Text(
document?.title ?? '',
maxLines: 10,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Colors.black,
fontSize: 14,
),
? ((document?.tags ?? []).isNotEmpty)
? Padding(
padding: const EdgeInsets.only(top: 8.0),
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 40,
child: ListView(
padding: const EdgeInsets.all(0),
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: [
for (final tag in document?.tags ?? [])
Padding(
padding: const EdgeInsets.only(right: 6),
child: Tagchip(tag: tag),
),
],
),
),
)
: null
: Column(
children: [
Text(
document?.title ?? '',
maxLines: 10,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Colors.black,
fontSize: 14,
),
),
if ((document?.tags ?? []).isNotEmpty)
SizedBox(
width: MediaQuery.of(context).size.width,
height: 40,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
for (final tag in document?.tags ?? [])
Padding(
padding: const EdgeInsets.only(right: 6),
child: Tagchip(tag: tag),
),
],
),
),
],
),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand All @@ -281,8 +321,7 @@ class NoticeTile extends StatelessWidget {
? "${document?.date.split('-')[0]} ${DateFormat('MMM').format(DateTime(0, int.parse(document?.date.split('-')[1] ?? '0')))}"
: timeago
.format(DateTime.parse(
document?.createdAt.toString() ?? '0')
.add(const Duration(minutes: 40)))
document?.createdAt.toString() ?? '0'))
.replaceAll('about', '')
.replaceAll('hour', 'hr')
.replaceAll('minute', 'min')
Expand Down Expand Up @@ -316,3 +355,26 @@ class NoticeTile extends StatelessWidget {
);
}
}

class Tagchip extends StatelessWidget {
const Tagchip({
Key? key,
required this.tag,
}) : super(key: key);

final String tag;

@override
Widget build(BuildContext context) {
return Chip(
backgroundColor: Colors.black.withOpacity(0.01),
label: Text(tag),
padding: const EdgeInsets.all(0),
labelStyle: TextStyle(
color: Colors.black.withOpacity(0.8),
fontSize: 12,
),
visualDensity: VisualDensity.compact,
);
}
}

0 comments on commit d6ff822

Please sign in to comment.