pikapika/lib/screens/components/ComicInfoCard.dart

370 lines
13 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Cross.dart';
import 'package:pikapika/basic/Entities.dart';
import 'package:pikapika/basic/Method.dart';
import 'package:pikapika/screens/SearchScreen.dart';
2022-01-18 06:01:01 +00:00
import 'package:pikapika/basic/Navigator.dart';
2021-09-29 23:57:09 +00:00
import '../ComicsScreen.dart';
import 'Images.dart';
// 漫画卡片
class ComicInfoCard extends StatefulWidget {
final bool linkItem;
final ComicSimple info;
2022-03-27 06:19:08 +00:00
final bool viewed;
2021-09-29 23:57:09 +00:00
2022-03-27 06:19:08 +00:00
const ComicInfoCard(
this.info, {
Key? key,
this.linkItem = false,
this.viewed = false,
}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _ComicInfoCard();
}
class _ComicInfoCard extends State<ComicInfoCard> {
bool _favouriteLoading = false;
bool _likeLoading = false;
@override
Widget build(BuildContext context) {
var info = widget.info;
var theme = Theme.of(context);
var view = info is ComicInfo ? info.viewsCount : 0;
bool? like = info is ComicInfo ? info.isLiked : null;
bool? favourite = info is ComicInfo ? (info).isFavourite : null;
return Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.all(5),
2021-09-29 23:57:09 +00:00
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: theme.dividerColor,
),
),
),
child: Row(
children: [
Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.only(right: 10),
2021-09-29 23:57:09 +00:00
child: RemoteImage(
fileServer: info.thumb.fileServer,
path: info.thumb.path,
width: imageWidth,
height: imageHeight,
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
widget.linkItem
? GestureDetector(
onLongPress: () {
confirmCopy(context, info.title);
},
child: Text(info.title, style: titleStyle),
)
: Text(info.title, style: titleStyle),
Container(height: 5),
widget.linkItem
? InkWell(
onTap: () {
navPushOrReplace(
context,
(context) =>
SearchScreen(keyword: info.author));
},
onLongPress: () {
confirmCopy(context, info.author);
},
child: Text(info.author, style: authorStyle),
)
: Text(info.author, style: authorStyle),
Container(height: 5),
Text.rich(
widget.linkItem
? TextSpan(
children: [
2022-03-19 04:12:27 +00:00
const TextSpan(text: '分类 :'),
2021-09-29 23:57:09 +00:00
...info.categories.map(
(e) => TextSpan(
children: [
2022-03-19 04:12:27 +00:00
const TextSpan(text: ' '),
2021-09-29 23:57:09 +00:00
TextSpan(
text: e,
recognizer: TapGestureRecognizer()
..onTap = () => navPushOrReplace(
context,
(context) => ComicsScreen(
category: e,
),
),
),
],
),
),
],
)
: TextSpan(
text: "分类 : ${info.categories.join(' ')}"),
style: TextStyle(
fontSize: 13,
color: Theme.of(context)
.textTheme
.bodyText1!
.color!
.withAlpha(0xCC),
),
),
Container(height: 5),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
runSpacing: 5,
children: [
...info.likesCount > 0
? [
iconFavorite,
iconSpacing,
Text(
'${info.likesCount}',
style: iconLabelStyle,
strutStyle: iconLabelStrutStyle,
),
iconMargin,
]
: [],
...(view > 0
? [
iconVisibility,
iconSpacing,
Text(
'$view',
style: iconLabelStyle,
strutStyle: iconLabelStrutStyle,
),
iconMargin,
]
: []),
2021-12-01 01:17:15 +00:00
...(info.epsCount > 0
? [
Text.rich(TextSpan(children: [
2022-03-19 04:12:27 +00:00
const WidgetSpan(child: iconPage),
2021-12-01 01:17:15 +00:00
WidgetSpan(child: iconSpacing),
WidgetSpan(
child: Text(
2021-09-29 23:57:09 +00:00
"${info.epsCount}E / ${info.pagesCount}P",
style: countLabelStyle,
strutStyle: iconLabelStrutStyle,
2021-12-01 01:17:15 +00:00
softWrap: false,
)),
WidgetSpan(child: iconMargin),
])),
]
: []),
2021-09-29 23:57:09 +00:00
iconMargin,
],
),
],
),
),
2022-03-17 03:31:25 +00:00
SizedBox(
2021-09-29 23:57:09 +00:00
height: imageHeight,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
buildFinished(info.finished),
2022-03-27 06:19:08 +00:00
...buildViewed(widget.viewed),
2021-09-29 23:57:09 +00:00
Expanded(child: Container()),
...(like == null
? []
: [
Container(height: 10),
2022-03-17 03:31:25 +00:00
SizedBox(
height: 26,
child: _likeLoading
? IconButton(
2022-03-19 04:12:27 +00:00
color: Colors.pink[400],
onPressed: () {},
icon: const Icon(
Icons.sync,
),
)
: IconButton(
2022-03-19 04:12:27 +00:00
color: Colors.pink[400],
onPressed: _changeLike,
icon: Icon(
like
? Icons.favorite
: Icons.favorite_border,
),
),
),
2021-09-29 23:57:09 +00:00
]),
...(favourite == null
? []
: [
Container(height: 10),
2022-03-17 03:31:25 +00:00
SizedBox(
height: 26,
child: _favouriteLoading
? IconButton(
2022-03-19 04:12:27 +00:00
color: Colors.pink[400],
onPressed: () {},
icon: const Icon(
Icons.sync,
),
)
: IconButton(
2022-03-19 04:12:27 +00:00
color: Colors.pink[400],
onPressed: _changeFavourite,
icon: Icon(
favourite
? Icons.bookmark
: Icons.bookmark_border,
),
),
),
2021-09-29 23:57:09 +00:00
]),
Container(height: 10),
2021-09-29 23:57:09 +00:00
],
),
),
],
),
),
],
),
);
}
Future _changeFavourite() async {
setState(() {
_favouriteLoading = true;
});
try {
var rst = await method.switchFavourite(widget.info.id);
setState(() {
(widget.info as ComicInfo).isFavourite = !rst.startsWith("un");
});
} finally {
setState(() {
_favouriteLoading = false;
});
}
}
Future _changeLike() async {
setState(() {
_likeLoading = true;
});
try {
var rst = await method.switchLike(widget.info.id);
setState(() {
(widget.info as ComicInfo).isLiked = !rst.startsWith("un");
});
} finally {
setState(() {
_likeLoading = false;
});
}
}
}
double imageWidth = 210 / 3.15;
double imageHeight = 315 / 3.15;
Widget buildFinished(bool comicFinished) {
if (comicFinished) {
return Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.only(left: 8, right: 8),
2021-09-29 23:57:09 +00:00
decoration: BoxDecoration(
color: Colors.orange.shade800,
borderRadius: BorderRadius.circular(30),
),
2022-03-19 04:12:27 +00:00
child: const Text(
2021-09-29 23:57:09 +00:00
"完结",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 1.2,
),
strutStyle: StrutStyle(
height: 1.2,
),
),
);
}
return Container();
}
2022-03-27 06:19:08 +00:00
List<Widget> buildViewed(viewed) {
if (!viewed) {
return [];
}
return [
Container(height: 5),
Container(
padding: const EdgeInsets.only(left: 8, right: 8),
decoration: BoxDecoration(
color: Colors.yellow.shade800,
borderRadius: BorderRadius.circular(30),
),
child: const Text(
"看过",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 1.2,
),
strutStyle: StrutStyle(
height: 1.2,
),
),
),
];
}
2021-09-29 23:57:09 +00:00
const double _iconSize = 15;
final iconFavorite =
Icon(Icons.favorite, size: _iconSize, color: Colors.pink[400]);
final iconDownload =
Icon(Icons.download_rounded, size: _iconSize, color: Colors.pink[400]);
final iconVisibility =
Icon(Icons.visibility, size: _iconSize, color: Colors.pink[400]);
final iconLabelStyle = TextStyle(
fontSize: 13,
color: Colors.pink.shade400,
height: 1.2,
);
2022-03-19 04:12:27 +00:00
const iconLabelStrutStyle = StrutStyle(
2021-09-29 23:57:09 +00:00
height: 1.2,
);
2022-03-19 04:12:27 +00:00
const iconPage =
2021-09-29 23:57:09 +00:00
Icon(Icons.ballot_outlined, size: _iconSize, color: Colors.grey);
2022-03-19 04:12:27 +00:00
const countLabelStyle = TextStyle(
2021-09-29 23:57:09 +00:00
fontSize: 13,
color: Colors.grey,
height: 1.2,
);
final iconMargin = Container(width: 20);
final iconSpacing = Container(width: 5);
2022-03-19 04:12:27 +00:00
const titleStyle = TextStyle(fontWeight: FontWeight.bold);
2021-09-29 23:57:09 +00:00
final authorStyle = TextStyle(
fontSize: 13,
color: Colors.pink.shade300,
);