following artworks page

This commit is contained in:
wgh19
2024-05-13 20:14:50 +08:00
parent 13ef786280
commit f3125ddc9a
4 changed files with 115 additions and 1 deletions

View File

@@ -336,4 +336,15 @@ class Network {
return Res.error(res.errorMessage);
}
}
Future<Res<List<Illust>>> getFollowingArtworks(String restrict, [String? nextUrl]) async {
var res = await apiGet(nextUrl ?? "/v2/illust/follow?restrict=$restrict");
if (res.success) {
return Res(
(res.data["illusts"] as List).map((e) => Illust.fromJson(e)).toList(),
subData: res.data["next_url"]);
} else {
return Res.error(res.errorMessage);
}
}
}

View File

@@ -0,0 +1,95 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/utils/translation.dart';
import '../components/illust_widget.dart';
import '../components/loading.dart';
import '../components/segmented_button.dart';
import '../network/network.dart';
class FollowingArtworksPage extends StatefulWidget {
const FollowingArtworksPage({super.key});
@override
State<FollowingArtworksPage> createState() => _FollowingArtworksPageState();
}
class _FollowingArtworksPageState extends State<FollowingArtworksPage> {
String restrict = "all";
@override
Widget build(BuildContext context) {
return Column(
children: [
buildTab(),
Expanded(
child: _OneFollowingPage(restrict, key: Key(restrict),),
)
],
);
}
Widget buildTab() {
return SegmentedButton(
options: [
SegmentedButtonOption("all", "All".tl),
SegmentedButtonOption("public", "Public".tl),
SegmentedButtonOption("private", "Private".tl),
],
onPressed: (key) {
if(key != restrict) {
setState(() {
restrict = key;
});
}
},
value: restrict,
).padding(const EdgeInsets.symmetric(vertical: 8, horizontal: 8));
}
}
class _OneFollowingPage extends StatefulWidget {
const _OneFollowingPage(this.restrict, {super.key});
final String restrict;
@override
State<_OneFollowingPage> createState() => _OneFollowingPageState();
}
class _OneFollowingPageState extends MultiPageLoadingState<_OneFollowingPage, Illust> {
@override
Widget buildContent(BuildContext context, final List<Illust> data) {
return LayoutBuilder(builder: (context, constrains){
return MasonryGridView.builder(
gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 240,
),
itemCount: data.length,
itemBuilder: (context, index) {
if(index == data.length - 1){
nextPage();
}
return IllustWidget(data[index]);
},
);
});
}
String? nextUrl;
@override
Future<Res<List<Illust>>> loadData(page) async{
if(nextUrl == "end") {
return Res.error("No more data");
}
var res = await Network().getFollowingArtworks(widget.restrict, nextUrl);
if(!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}

View File

@@ -9,6 +9,7 @@ import "package:pixes/foundation/app.dart";
import "package:pixes/network/network.dart";
import "package:pixes/pages/bookmarks.dart";
import "package:pixes/pages/explore_page.dart";
import "package:pixes/pages/following_artworks.dart";
import "package:pixes/pages/recommendation_page.dart";
import "package:pixes/pages/login_page.dart";
import "package:pixes/pages/search_page.dart";
@@ -99,6 +100,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
title: Text('Search'.tl),
body: const SizedBox.shrink(),
),
PaneItemSeparator(),
PaneItemHeader(header: Text("Artwork".tl).paddingVertical(4).paddingLeft(8)),
PaneItem(
icon: const Icon(MdIcons.star_border, size: 20,),
@@ -110,6 +112,11 @@ class _MainPageState extends State<MainPage> with WindowListener {
title: Text('Bookmarks'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.interests_outlined, size: 20),
title: Text('Following'.tl),
body: const SizedBox.shrink(),
),
PaneItemSeparator(),
PaneItem(
icon: const Icon(MdIcons.explore_outlined, size: 20),
@@ -138,6 +145,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
() => const SearchPage(),
() => const RecommendationPage(),
() => const BookMarkedArtworkPage(),
() => const FollowingArtworksPage(),
() => const ExplorePage(),
() => const SettingsPage(),
];

View File

@@ -106,7 +106,7 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
child: Column(
children: [
buildHeader("Infomation".tl),
buildItem(icon: MdIcons.comment_outlined, title: "Comment".tl, content: data!.comment),
buildItem(icon: MdIcons.comment_outlined, title: "Introduction".tl, content: data!.comment),
buildItem(icon: MdIcons.cake_outlined, title: "Birthday".tl, content: data!.birth),
buildItem(icon: MdIcons.location_city_outlined, title: "Region", content: data!.region),
buildItem(icon: MdIcons.work_outline, title: "Job".tl, content: data!.job),