pikapika/lib/screens/RankingsScreen.dart

218 lines
5.9 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/basic/config/ListLayout.dart';
import 'package:pikapika/basic/config/ShadowCategories.dart';
2022-06-30 11:16:10 +00:00
import 'package:pikapika/screens/components/Avatar.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart';
2021-09-29 23:57:09 +00:00
2022-06-30 11:16:10 +00:00
import '../basic/Cross.dart';
import '../basic/Navigator.dart';
2023-02-16 08:33:16 +00:00
import '../basic/config/Address.dart';
2022-06-30 11:16:10 +00:00
import 'ComicsScreen.dart';
2021-09-29 23:57:09 +00:00
import 'components/ComicListBuilder.dart';
2023-02-16 08:33:16 +00:00
import 'components/Common.dart';
2022-06-30 11:16:10 +00:00
import 'components/FitButton.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 RankingsScreen extends StatelessWidget {
2022-03-19 04:12:27 +00:00
const RankingsScreen({Key? key}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
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
var theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
2022-03-19 04:12:27 +00:00
title: const Text('排行榜'),
2021-09-29 23:57:09 +00:00
actions: [
2023-04-07 01:56:11 +00:00
commonPopMenu(context),
addressPopMenu(context),
2021-09-29 23:57:09 +00:00
],
),
body: DefaultTabController(
2022-06-30 11:16:10 +00:00
length: 4,
2021-09-29 23:57:09 +00:00
child: Column(
children: [
Container(
height: 40,
color: theme.colorScheme.secondary.withOpacity(.025),
child: TabBar(
indicatorColor: theme.colorScheme.secondary,
labelColor: theme.colorScheme.secondary,
2022-03-19 04:12:27 +00:00
tabs: const [
2021-09-29 23:57:09 +00:00
Tab(text: ''),
Tab(text: ''),
Tab(text: ''),
2022-06-30 11:16:10 +00:00
Tab(text: ''),
2021-09-29 23:57:09 +00:00
],
),
),
2022-03-19 04:12:27 +00:00
const Expanded(
2021-09-29 23:57:09 +00:00
child: TabBarView(
children: [
_Leaderboard("H24"),
_Leaderboard("D7"),
_Leaderboard("D30"),
2022-06-30 11:16:10 +00:00
_KnightLeaderBoard(),
2021-09-29 23:57:09 +00:00
],
),
),
],
),
),
);
}
}
class _Leaderboard extends StatefulWidget {
final String type;
2022-03-19 04:12:27 +00:00
const _Leaderboard(this.type);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _LeaderboardState();
}
class _LeaderboardState extends State<_Leaderboard> {
@override
Widget build(BuildContext context) {
2022-07-12 07:28:47 +00:00
return ComicListBuilder(() => method.leaderboard(widget.type));
2021-09-29 23:57:09 +00:00
}
}
2022-06-30 11:16:10 +00:00
class _KnightLeaderBoard extends StatefulWidget {
const _KnightLeaderBoard();
@override
State<StatefulWidget> createState() => _KnightLeaderBoardState();
}
class _KnightLeaderBoardState extends State<_KnightLeaderBoard> {
Future<List<Knight>> _future = method.leaderboardOfKnight();
2022-07-04 02:02:09 +00:00
Key _key = UniqueKey();
2022-06-30 11:16:10 +00:00
@override
Widget build(BuildContext context) {
return ContentBuilder(
2022-07-04 02:02:09 +00:00
key: _key,
2022-06-30 11:16:10 +00:00
future: _future,
onRefresh: () async {
setState(() {
_future = method.leaderboardOfKnight();
2022-07-04 02:02:09 +00:00
_key = UniqueKey();
2022-06-30 11:16:10 +00:00
});
},
successBuilder: (
BuildContext context,
AsyncSnapshot<List<Knight>> snapshot,
) {
return RefreshIndicator(
onRefresh: () async {
setState(() {
_future = method.leaderboardOfKnight();
});
},
child: ListView(children: [
...snapshot.requireData.map(_knightCard).toList(),
SizedBox(
height: 80,
child: FitButton(
text: '刷新',
onPressed: () async {
setState(() {
_future = method.leaderboardOfKnight();
});
},
),
),
]),
);
},
);
}
Widget _knightCard(Knight e) {
final theme = Theme.of(context);
var nameStyle = const TextStyle(fontWeight: FontWeight.bold);
var levelStyle = TextStyle(
fontSize: 12, color: theme.colorScheme.secondary.withOpacity(.8));
var connectStyle =
TextStyle(color: theme.textTheme.bodyText1?.color?.withOpacity(.8));
var datetimeStyle = TextStyle(
color: theme.textTheme.bodyText1?.color?.withOpacity(.6), fontSize: 12);
final card = Container(
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
width: .25,
style: BorderStyle.solid,
color: Colors.grey.shade500.withOpacity(.5),
),
bottom: BorderSide(
width: .25,
style: BorderStyle.solid,
color: Colors.grey.shade500.withOpacity(.5),
),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Avatar(e.avatar),
Container(width: 5),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(e.name, style: nameStyle),
Expanded(child: Container()),
Text(
"${e.comicsUploaded}",
style: datetimeStyle,
),
],
),
Text("Lv. ${e.level} (${e.title})", style: levelStyle),
Text(e.slogan ?? "", style: connectStyle),
],
),
),
],
),
);
return InkWell(
onTap: () {
navPushOrReplace(
context,
2022-07-12 07:28:47 +00:00
(context) => ComicsScreen(
2022-06-30 11:16:10 +00:00
creatorId: e.id,
creatorName: e.name,
),
);
},
onLongPress: () {
confirmCopy(
context,
e.name,
);
},
child: card,
);
}
}