mirror of
https://github.com/dstark5/Openlib.git
synced 2025-07-04 21:58:35 +08:00
178 lines
6.0 KiB
Dart
178 lines
6.0 KiB
Dart
// Flutter imports:
|
|
import 'package:flutter/material.dart';
|
|
|
|
// Package imports:
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
// Project imports:
|
|
import 'package:openlib/ui/extensions.dart';
|
|
|
|
String? getFileType(String? info) {
|
|
if (info != null && info.isNotEmpty) {
|
|
info = info.toLowerCase();
|
|
if (info.contains('pdf')) return "PDF";
|
|
if (info.contains('epub')) return "Epub";
|
|
if (info.contains('cbr')) return "Cbr";
|
|
if (info.contains('cbz')) return "Cbz";
|
|
return null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
class BookInfoCard extends StatelessWidget {
|
|
const BookInfoCard(
|
|
{super.key,
|
|
required this.title,
|
|
required this.author,
|
|
required this.publisher,
|
|
required this.thumbnail,
|
|
required this.info,
|
|
required this.link,
|
|
required this.onClick});
|
|
|
|
final String title;
|
|
final String author;
|
|
final String publisher;
|
|
final String? thumbnail;
|
|
final String? info;
|
|
final String link;
|
|
final VoidCallback onClick;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
String? fileType = getFileType(info);
|
|
|
|
return InkWell(
|
|
onTap: onClick,
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 120,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5),
|
|
color: Theme.of(context).colorScheme.tertiaryContainer,
|
|
),
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
CachedNetworkImage(
|
|
height: 120,
|
|
width: 90,
|
|
imageUrl: thumbnail ?? "",
|
|
imageBuilder: (context, imageProvider) => Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: const BorderRadius.all(Radius.circular(5)),
|
|
image: DecorationImage(
|
|
image: imageProvider,
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
),
|
|
placeholder: (context, url) => Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5),
|
|
color: "#F8C0C8".toColor(),
|
|
),
|
|
height: 120,
|
|
width: 90,
|
|
),
|
|
errorWidget: (context, url, error) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5),
|
|
color: "#F8C0C8".toColor(),
|
|
),
|
|
height: 120,
|
|
width: 90,
|
|
child: const Center(
|
|
child: Icon(Icons.image_rounded),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(5),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.bold,
|
|
color: Theme.of(context).colorScheme.tertiary,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 2,
|
|
),
|
|
Text(
|
|
publisher,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
color:
|
|
Theme.of(context).textTheme.headlineMedium?.color,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 1,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
if (fileType != null)
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: "#a5a5a5".toColor(),
|
|
borderRadius: BorderRadius.circular(2.5),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(3, 2, 3, 2),
|
|
child: Text(
|
|
fileType,
|
|
style: const TextStyle(
|
|
fontSize: 8.5,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
letterSpacing: 0.5,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
),
|
|
if (fileType != null)
|
|
const SizedBox(
|
|
width: 3,
|
|
),
|
|
Expanded(
|
|
child: Text(
|
|
author,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.bold,
|
|
color: Theme.of(context)
|
|
.textTheme
|
|
.headlineSmall
|
|
?.color,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|