feat(ui): Implement a generic list item

This commit is contained in:
2023-02-04 11:58:15 +01:00
parent a60e9e8e81
commit cd1291a192
3 changed files with 52 additions and 66 deletions

View File

@@ -0,0 +1,106 @@
import 'package:anitrack/src/data/anime.dart';
import 'package:anitrack/src/ui/widgets/swipe_icon.dart';
import 'package:flutter/material.dart';
import 'package:swipeable_tile/swipeable_tile.dart';
/// A widget for displaying simple data about an anime in the listview
class ListItem extends StatelessWidget {
ListItem({
required this.thumbnailUrl,
required this.title,
this.onLeftSwipe,
this.onRightSwipe,
this.extra = const [],
super.key,
});
/// URL for the cover image.
final String thumbnailUrl;
/// The title of the item
final String title;
/// Extra widgets.
final List<Widget> extra;
/// Callbacks for the swipe functionality.
final void Function()? onLeftSwipe;
final void Function()? onRightSwipe;
@override
Widget build(BuildContext context) {
return SwipeableTile.swipeToTrigger(
onSwiped: (direction) {
if (direction == SwipeDirection.endToStart) {
onRightSwipe!();
} else if (direction == SwipeDirection.startToEnd) {
onLeftSwipe!();
}
},
// TODO(PapaTutuWawa): Fix
key: UniqueKey(),
backgroundBuilder: (_, direction, __) {
if (direction == SwipeDirection.endToStart) {
return Align(
alignment: Alignment.centerRight,
child: SwipeIcon(
Icons.add,
),
);
} else if (direction == SwipeDirection.startToEnd) {
return Align(
alignment: Alignment.centerLeft,
child: SwipeIcon(
Icons.remove,
),
);
}
return Container();
},
color: Theme.of(context).scaffoldBackgroundColor,
direction: onRightSwipe != null && onLeftSwipe != null ?
SwipeDirection.horizontal :
SwipeDirection.none,
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: SizedBox(
width: 100,
child: Image.network(
thumbnailUrl,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.titleLarge,
maxLines: 2,
softWrap: true,
overflow: TextOverflow.ellipsis,
),
...extra,
],
),
),
),
],
),
),
);
}
}