feat(ui): Implement a generic list item
This commit is contained in:
106
lib/src/ui/widgets/list_item.dart
Normal file
106
lib/src/ui/widgets/list_item.dart
Normal 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,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user