Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

add character modal sheet

Predidite849f06d7ea1
diff --git a/lib/bean/card/character_card.dart b/lib/bean/card/character_card.dart
index 784fa816..08df54ac 100644
--- a/lib/bean/card/character_card.dart
+++ b/lib/bean/card/character_card.dart
@@ -1,5 +1,7 @@
+import 'package:kazumi/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:kazumi/modules/characters/character_item.dart';
+import 'package:kazumi/pages/info/character_page.dart';
class CharacterCard extends StatelessWidget {
const CharacterCard({
@@ -11,52 +13,34 @@ class CharacterCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return Card(
- color: Theme.of(context).colorScheme.secondaryContainer,
- child: ExpansionTile(
- shape: const RoundedRectangleBorder(
- side: BorderSide.none,
- borderRadius: BorderRadius.zero,
- ),
- title: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- CircleAvatar(
- backgroundImage: NetworkImage(characterItem.avator.grid),
- ),
- const SizedBox(width: 8),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- width: 150,
- child: Text(characterItem.name,
- overflow: TextOverflow.clip, maxLines: 1)),
- Text(characterItem.actorList.isEmpty
- ? ''
- : characterItem.actorList[0].name),
- ],
- ),
- const Expanded(child: SizedBox(height: 10)),
- Text(characterItem.relation)
- ],
- ),
- ],
- ),
- children: [
- Align(
- alignment: Alignment.centerLeft,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(characterItem.actorList.isEmpty
- ? ''
- : characterItem.actorList[0].shortSummary),
- ),
- ),
- ],
+ return ListTile(
+ leading: CircleAvatar(
+ backgroundImage: NetworkImage(characterItem.avator.grid),
),
+ title: Text(
+ characterItem.name,
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ ),
+ subtitle: characterItem.actorList.isNotEmpty
+ ? Text(characterItem.actorList[0].name)
+ : null,
+ trailing: Text(characterItem.relation),
+ onTap: () {
+ showModalBottomSheet(
+ barrierColor: Colors.transparent,
+ isScrollControlled: true,
+ constraints: BoxConstraints(
+ maxHeight: MediaQuery.of(context).size.height * 3 / 4,
+ maxWidth: (Utils.isDesktop() || Utils.isTablet())
+ ? MediaQuery.of(context).size.width * 9 / 16
+ : MediaQuery.of(context).size.width),
+ clipBehavior: Clip.antiAlias,
+ context: context,
+ builder: (context) {
+ return CharacterPage(characterID: characterItem.id);
+ });
+ },
);
}
}
diff --git a/lib/modules/character/character_full_item.dart b/lib/modules/character/character_full_item.dart
new file mode 100644
index 00000000..87cc01a3
--- /dev/null
+++ b/lib/modules/character/character_full_item.dart
@@ -0,0 +1,49 @@
+class CharacterFullItem {
+ final int id;
+ final String name;
+ final String nameCN;
+ final String info;
+ final String summary;
+ final String image;
+
+ CharacterFullItem({
+ required this.id,
+ required this.name,
+ required this.nameCN,
+ required this.info,
+ required this.summary,
+ required this.image,
+ });
+
+ factory CharacterFullItem.fromJson(Map<String, dynamic> json) {
+ return CharacterFullItem(
+ id: json['id'] ?? 0,
+ name: json['name'] ?? '',
+ nameCN: json['nameCN'] ?? '',
+ info: json['info'] ?? '',
+ summary: json['summary'] ?? '',
+ image: json['images']['large'] ?? '',
+ );
+ }
+
+ factory CharacterFullItem.fromTemplate() {
+ return CharacterFullItem(
+ id: 0,
+ name: '',
+ nameCN: '',
+ info: '',
+ summary: '',
+ image: '',
+ );
+ }
+
+ Map<String, dynamic> toJson() {
+ return {
+ 'id': id,
+ 'name': name,
+ 'nameCN': nameCN,
+ 'info': info,
+ 'summary': summary,
+ };
+ }
+}
diff --git a/lib/modules/characters/character_response.dart b/lib/modules/characters/character_response.dart
deleted file mode 100644
index 9f10bce5..00000000
--- a/lib/modules/characters/character_response.dart
+++ /dev/null
@@ -1,29 +0,0 @@
-import 'package:kazumi/modules/characters/character_item.dart';
-
-class CharacterResponse {
- final List<CharacterItem> characterList;
-
- CharacterResponse({
- required this.characterList,
- });
-
- factory CharacterResponse.fromJson(List list) {
- List<CharacterItem> resCharacterList =
- list.map((i) => CharacterItem.fromJson(i)).toList();
- return CharacterResponse(
- characterList: resCharacterList,
- );
- }
-
- factory CharacterResponse.fromTemplate() {
- return CharacterResponse(
- characterList: [],
- );
- }
-
- Map<String, dynamic> toJson() {
- return {
- 'characterList': characterList.map((e) => e.toJson()).toList(),
- };
- }
-}
diff --git a/lib/modules/characters/characters_response.dart b/lib/modules/characters/characters_response.dart
new file mode 100644
index 00000000..f78e3bc2
--- /dev/null
+++ b/lib/modules/characters/characters_response.dart
@@ -0,0 +1,33 @@
+import 'package:kazumi/request/api.dart';
+import 'package:kazumi/modules/characters/character_item.dart';
+
+/// The response from [Api.bangumiInfoByID]
+/// It contains a list of [CharacterItem]
+/// It is used to show general information about seraval bangumi characters
+class CharactersResponse {
+ final List<CharacterItem> charactersList;
+
+ CharactersResponse({
+ required this.charactersList,
+ });
+
+ factory CharactersResponse.fromJson(List list) {
+ List<CharacterItem> resCharactersList =
+ list.map((i) => CharacterItem.fromJson(i)).toList();
+ return CharactersResponse(
+ charactersList: resCharactersList,
+ );
+ }
+
+ factory CharactersResponse.fromTemplate() {
+ return CharactersResponse(
+ charactersList: [],
+ );
+ }
+
+ Map<String, dynamic> toJson() {
+ return {
+ 'charactersList': charactersList.map((e) => e.toJson()).toList(),
+ };
+ }
+}
diff --git a/lib/pages/about/about_page.dart b/lib/pages/about/about_page.dart
index 052a5df2..566f1354 100644
--- a/lib/pages/about/about_page.dart
+++ b/lib/pages/about/about_page.dart
@@ -125,7 +125,6 @@ class _AboutPageState extends State<AboutPage> {
@override
Widget build(BuildContext context) {
- WidgetsBinding.instance.addPostFrameCallback((_) {});
return PopScope(
canPop: true,
onPopInvokedWithResult: (bool didPop, Object? result) async {
diff --git a/lib/pages/info/character_page.dart b/lib/pages/info/character_page.dart
new file mode 100644
index 00000000..4f537237
--- /dev/null
+++ b/lib/pages/info/character_page.dart
@@ -0,0 +1,188 @@
+import 'package:flutter/material.dart';
+import 'package:kazumi/modules/character/character_full_item.dart';
+import 'package:kazumi/request/bangumi.dart';
+import 'package:kazumi/bean/card/network_img_layer.dart';
+
+class CharacterPage extends StatefulWidget {
+ const CharacterPage({super.key, required this.characterID});
+
+ final int characterID;
+
+ @override
+ State<CharacterPage> createState() => _CharacterPageState();
+}
+
+class _CharacterPageState extends State<CharacterPage> {
+ late CharacterFullItem characterFullItem;
+ bool loadingCharacter = true;
+
+ Future<void> loadCharacter() async {
+ setState(() {
+ loadingCharacter = true;
+ });
+ await BangumiHTTP.getCharacterByCharacterID(widget.characterID)
+ .then((character) {
+ characterFullItem = character;
+ });
+ setState(() {
+ loadingCharacter = false;
+ });
+ }
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ loadCharacter();
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return DefaultTabController(
+ length: 2,
+ child: Scaffold(
+ body: Column(
+ children: [
+ const PreferredSize(
+ preferredSize: Size.fromHeight(kToolbarHeight),
+ child: Material(
+ child: TabBar(
+ tabs: [
+ Tab(text: '人物资料'),
+ Tab(text: '吐槽箱'),
+ ],
+ ),
+ ),
+ ),
+ Expanded(
+ child: TabBarView(
+ children: [characterInfoBody, characterCommentsBody],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget get characterInfoBody {
+ return Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: LayoutBuilder(builder: (context, constraints) {
+ return Column(
+ children: [
+ Expanded(
+ child: loadingCharacter
+ ? const Center(child: CircularProgressIndicator())
+ : SizedBox(
+ width: double.infinity,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ width: constraints.maxWidth * 0.3,
+ height: constraints.maxHeight,
+ child: NetworkImgLayer(
+ width: constraints.maxWidth,
+ height: constraints.maxHeight,
+ src: characterFullItem.image,
+ ),
+ ),
+ Expanded(
+ child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.all(16.0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ characterFullItem.name,
+ style: Theme.of(context)
+ .textTheme
+ .headlineSmall
+ ?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: Theme.of(context)
+ .colorScheme
+ .tertiary,
+ ),
+ overflow: TextOverflow.ellipsis,
+ maxLines: 2,
+ ),
+ Padding(
+ padding: const EdgeInsets.only(
+ top: 4.0, bottom: 12.0),
+ child: Text(
+ characterFullItem.nameCN,
+ style: Theme.of(context)
+ .textTheme
+ .titleMedium
+ ?.copyWith(
+ color: Colors.grey[700],
+ ),
+ ),
+ ),
+ const Divider(),
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ vertical: 8.0),
+ child: Text(
+ '基本信息',
+ style: Theme.of(context)
+ .textTheme
+ .titleSmall
+ ?.copyWith(
+ fontWeight: FontWeight.bold,
+ ),
+ ),
+ ),
+ Text(
+ characterFullItem.info,
+ style: Theme.of(context)
+ .textTheme
+ .bodyMedium,
+ textAlign: TextAlign.justify,
+ ),
+ const SizedBox(height: 16.0),
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ vertical: 8.0),
+ child: Text(
+ '角色简介',
+ style: Theme.of(context)
+ .textTheme
+ .titleSmall
+ ?.copyWith(
+ fontWeight: FontWeight.bold,
+ ),
+ ),
+ ),
+ Text(
+ characterFullItem.summary,
+ style: Theme.of(context)
+ .textTheme
+ .bodyMedium,
+ textAlign: TextAlign.justify,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ }),
+ );
+ }
+
+ Widget get characterCommentsBody {
+ return const Center(
+ child: Text('施工中'),
+ );
+ }
+}
diff --git a/lib/pages/info/info_controller.dart b/lib/pages/info/info_controller.dart
index 71a65bd5..924dac24 100644
--- a/lib/pages/info/info_controller.dart
+++ b/lib/pages/info/info_controller.dart
@@ -96,8 +96,8 @@ abstract class _InfoController with Store {
Future<void> queryBangumiCharactersByID(int id) async {
characterList.clear();
- await BangumiHTTP.getCharatersByID(id).then((value) {
- characterList.addAll(value.characterList);
+ await BangumiHTTP.getCharatersByBangumiID(id).then((value) {
+ characterList.addAll(value.charactersList);
});
Map<String, int> relationValue = {
'主角': 1,
diff --git a/lib/request/api.dart b/lib/request/api.dart
index d792492f..83817533 100644
--- a/lib/request/api.dart
+++ b/lib/request/api.dart
@@ -29,6 +29,7 @@ class Api {
// Next条目API
static const String bangumiTrendsNext = 'https://next.bgm.tv/p1/trending/subjects';
static const String bangumiInfoByIDNext = 'https://next.bgm.tv/p1/subjects/';
+ static const String characterInfoByCharacterIDNext = 'https://next.bgm.tv/p1/characters/{0}';
static const String bangumiEpisodeByIDNext = 'https://next.bgm.tv/p1/episodes/';
// 弹弹Play
static const String dandanIndex = 'https://www.dandanplay.com/';
diff --git a/lib/request/bangumi.dart b/lib/request/bangumi.dart
index 331a619b..2d2463b0 100644
--- a/lib/request/bangumi.dart
+++ b/lib/request/bangumi.dart
@@ -6,8 +6,9 @@ import 'package:kazumi/request/api.dart';
import 'package:kazumi/request/request.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/modules/comments/comment_response.dart';
-import 'package:kazumi/modules/characters/character_response.dart';
+import 'package:kazumi/modules/characters/characters_response.dart';
import 'package:kazumi/modules/bangumi/episode_item.dart';
+import 'package:kazumi/modules/character/character_full_item.dart';
class BangumiHTTP {
// why the api havn't been replaced by getCalendarBySearch?
@@ -267,17 +268,32 @@ class BangumiHTTP {
return commentResponse;
}
- static Future<CharacterResponse> getCharatersByID(int id) async {
- CharacterResponse characterResponse = CharacterResponse.fromTemplate();
+ static Future<CharactersResponse> getCharatersByBangumiID(int id) async {
+ CharactersResponse charactersResponse = CharactersResponse.fromTemplate();
try {
final res = await Request().get('${Api.bangumiInfoByID}$id/characters',
options: Options(headers: bangumiHTTPHeader));
final jsonData = res.data;
- characterResponse = CharacterResponse.fromJson(jsonData);
+ charactersResponse = CharactersResponse.fromJson(jsonData);
} catch (e) {
KazumiLogger().log(
Level.error, 'Resolve bangumi characters failed ${e.toString()}');
}
- return characterResponse;
+ return charactersResponse;
+ }
+
+ static Future<CharacterFullItem> getCharacterByCharacterID(int id) async {
+ CharacterFullItem characterFullItem = CharacterFullItem.fromTemplate();
+ try {
+ final res = await Request().get(
+ Api.formatUrl(Api.characterInfoByCharacterIDNext, [id]),
+ options: Options(headers: bangumiHTTPHeader));
+ final jsonData = res.data;
+ characterFullItem = CharacterFullItem.fromJson(jsonData);
+ } catch (e) {
+ KazumiLogger()
+ .log(Level.error, 'Resolve character info failed ${e.toString()}');
+ }
+ return characterFullItem;
}
}