pikapika/lib/screens/GameInfoScreen.dart

187 lines
6.7 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Entities.dart';
import 'package:pikapika/basic/Method.dart';
import 'package:pikapika/screens/components/CommentMainType.dart';
import 'package:pikapika/screens/components/ContentError.dart';
import 'package:pikapika/screens/components/ContentLoading.dart';
import 'package:pikapika/screens/components/Images.dart';
2021-09-29 23:57:09 +00:00
import 'GameDownloadScreen.dart';
2021-11-09 21:57:44 +00:00
import 'components/CommentList.dart';
2021-09-29 23:57:09 +00:00
import 'components/GameTitleCard.dart';
2022-03-19 04:12:27 +00:00
import 'components/RightClickPop.dart';
2021-09-29 23:57:09 +00:00
2021-10-26 11:04:23 +00:00
// 游戏详情
2021-09-29 23:57:09 +00:00
class GameInfoScreen extends StatefulWidget {
final String gameId;
2022-06-03 03:19:29 +00:00
const GameInfoScreen(this.gameId, {Key? key}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _GameInfoScreenState();
}
class _GameInfoScreenState extends State<GameInfoScreen> {
late var _future = method.game(widget.gameId);
2022-06-03 03:19:29 +00:00
late var _key = UniqueKey();
2021-09-29 23:57:09 +00:00
@override
2022-06-03 03:19:29 +00:00
Widget build(BuildContext context) {
2022-03-25 14:57:30 +00:00
return rightClickPop(
child: buildScreen(context),
context: context,
canPop: true,
);
2022-03-19 04:12:27 +00:00
}
Widget buildScreen(BuildContext context) {
2021-09-29 23:57:09 +00:00
return FutureBuilder(
2022-06-03 03:19:29 +00:00
key: _key,
2021-09-29 23:57:09 +00:00
future: _future,
builder: (BuildContext context, AsyncSnapshot<GameInfo> snapshot) {
if (snapshot.hasError) {
return Scaffold(
appBar: AppBar(
2022-03-19 04:12:27 +00:00
title: const Text('加载出错'),
2021-09-29 23:57:09 +00:00
),
body: ContentError(
error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async {
setState(() {
_future = method.game(widget.gameId);
2022-06-03 03:19:29 +00:00
_key = UniqueKey();
2021-09-29 23:57:09 +00:00
});
}),
);
}
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: AppBar(
2022-03-19 04:12:27 +00:00
title: const Text('加载中'),
2021-09-29 23:57:09 +00:00
),
2022-03-19 04:12:27 +00:00
body: const ContentLoading(label: '加载中'),
2021-09-29 23:57:09 +00:00
);
}
2022-03-19 04:12:27 +00:00
BorderRadius iconRadius = const BorderRadius.all(Radius.circular(6));
2021-09-29 23:57:09 +00:00
double screenShootMargin = 10;
double screenShootHeight = 200;
2022-03-19 04:12:27 +00:00
TextStyle descriptionStyle = const TextStyle();
2021-09-29 23:57:09 +00:00
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
var info = snapshot.data!;
2021-11-09 21:57:44 +00:00
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(info.title),
),
body: ListView(
children: [
GameTitleCard(info),
Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.only(
2021-11-09 21:57:44 +00:00
left: 20,
right: 20,
top: 5,
bottom: 10,
),
child: ClipRRect(
2022-06-03 03:19:29 +00:00
borderRadius:
const BorderRadius.all(Radius.circular(5)),
2021-11-09 21:57:44 +00:00
child: MaterialButton(
color: Theme.of(context).colorScheme.secondary,
textColor: Colors.white,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
2022-02-02 12:38:44 +00:00
builder: (context) => GameDownloadScreen(info),
),
2021-11-09 21:57:44 +00:00
);
},
child: Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.all(5),
child: const Text('下载'),
2021-11-09 21:57:44 +00:00
),
2021-11-09 02:38:04 +00:00
),
2021-09-29 23:57:09 +00:00
),
),
2021-11-09 21:57:44 +00:00
Container(
margin: EdgeInsets.only(
top: screenShootMargin,
bottom: screenShootMargin,
2021-09-29 23:57:09 +00:00
),
2021-11-09 21:57:44 +00:00
height: screenShootHeight,
child: ListView(
padding: EdgeInsets.only(
left: screenShootMargin,
right: screenShootMargin,
),
scrollDirection: Axis.horizontal,
children: info.screenshots
.map((e) => Container(
margin: EdgeInsets.only(
left: screenShootMargin,
right: screenShootMargin,
),
child: ClipRRect(
borderRadius: iconRadius,
child: RemoteImage(
height: screenShootHeight,
fileServer: e.fileServer,
path: e.path,
),
2021-09-29 23:57:09 +00:00
),
2021-11-09 21:57:44 +00:00
))
.toList(),
),
2021-09-29 23:57:09 +00:00
),
2021-11-09 21:57:44 +00:00
Container(height: 20),
2022-03-17 03:31:25 +00:00
Column(
children: [
Container(
height: 40,
color: Theme.of(context)
.colorScheme
.secondary
.withOpacity(.025),
child: TabBar(
tabs: <Widget>[
2022-03-19 04:12:27 +00:00
const Tab(text: '详情 '),
2022-03-17 03:31:25 +00:00
Tab(text: '评论 (${info.commentsCount})'),
],
indicatorColor:
Theme.of(context).colorScheme.secondary,
2022-06-03 03:19:29 +00:00
labelColor: Theme.of(context).colorScheme.secondary,
2022-03-17 03:31:25 +00:00
onTap: (val) async {
setState(() {
_tabIndex = val;
});
},
2021-11-09 21:57:44 +00:00
),
2022-03-17 03:31:25 +00:00
),
],
2021-11-09 21:57:44 +00:00
),
_tabIndex == 0
? Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.all(20),
2021-11-09 21:57:44 +00:00
child:
Text(info.description, style: descriptionStyle),
)
: CommentList(CommentMainType.GAME, info.id),
],
),
2021-09-29 23:57:09 +00:00
),
);
},
);
},
);
}
2021-11-09 21:57:44 +00:00
var _tabIndex = 0;
2021-09-29 23:57:09 +00:00
}