Initial commit

This commit is contained in:
wgh19
2024-05-13 09:36:23 +08:00
commit b095643cbc
160 changed files with 9956 additions and 0 deletions

94
lib/pages/bookmarks.dart Normal file
View File

@@ -0,0 +1,94 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/components/segmented_button.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/translation.dart';
import '../components/illust_widget.dart';
import '../components/loading.dart';
class BookMarkedArtworkPage extends StatefulWidget {
const BookMarkedArtworkPage({super.key});
@override
State<BookMarkedArtworkPage> createState() => _BookMarkedArtworkPageState();
}
class _BookMarkedArtworkPageState extends State<BookMarkedArtworkPage>{
String restrict = "public";
@override
Widget build(BuildContext context) {
return Column(
children: [
buildTab(),
Expanded(
child: _OneBookmarkedPage(restrict, key: Key(restrict),),
)
],
);
}
Widget buildTab() {
return SegmentedButton(
options: [
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 _OneBookmarkedPage extends StatefulWidget {
const _OneBookmarkedPage(this.restrict, {super.key});
final String restrict;
@override
State<_OneBookmarkedPage> createState() => _OneBookmarkedPageState();
}
class _OneBookmarkedPageState extends MultiPageLoadingState<_OneBookmarkedPage, 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().getBookmarkedIllusts(widget.restrict, nextUrl);
if(!res.error) {
nextUrl = res.subData;
nextUrl ?? "end";
}
return res;
}
}

View File

@@ -0,0 +1,12 @@
import 'package:flutter/widgets.dart';
class ExplorePage extends StatelessWidget {
const ExplorePage({super.key});
@override
Widget build(BuildContext context) {
return const Center(
child: Text("Explore"),
);
}
}

View File

499
lib/pages/illust_page.dart Normal file
View File

@@ -0,0 +1,499 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show Icons;
import 'package:pixes/components/animated_image.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/download.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/pages/image_page.dart';
import 'package:pixes/pages/user_info_page.dart';
import 'package:pixes/utils/translation.dart';
import '../components/color_scheme.dart';
const _kBottomBarHeight = 64.0;
class IllustPage extends StatefulWidget {
const IllustPage(this.illust, {super.key});
final Illust illust;
@override
State<IllustPage> createState() => _IllustPageState();
}
class _IllustPageState extends State<IllustPage> {
@override
Widget build(BuildContext context) {
return ColoredBox(
color: FluentTheme.of(context).micaBackgroundColor,
child: SizedBox.expand(
child: ColoredBox(
color: FluentTheme.of(context).scaffoldBackgroundColor,
child: LayoutBuilder(builder: (context, constrains) {
return Stack(
children: [
Positioned(
bottom: 0,
left: 0,
right: 0,
top: 0,
child: buildBody(constrains.maxWidth, constrains.maxHeight),
),
_BottomBar(widget.illust, constrains.maxHeight, constrains.maxWidth),
],
);
}),
),
),
);
}
Widget buildBody(double width, double height) {
return ListView.builder(
itemCount: widget.illust.images.length + 2,
itemBuilder: (context, index) {
return buildImage(width, height, index);
});
}
Widget buildImage(double width, double height, int index) {
if (index == 0) {
return Text(
widget.illust.title,
style: const TextStyle(fontSize: 24),
).paddingVertical(8).paddingHorizontal(12);
}
index--;
if (index == widget.illust.images.length) {
return const SizedBox(
height: _kBottomBarHeight,
);
}
var imageWidth = width;
var imageHeight = widget.illust.height * width / widget.illust.width;
if (imageHeight > height) {
// 确保图片能够完整显示在屏幕上
var scale = imageHeight / height;
imageWidth = imageWidth / scale;
imageHeight = height;
}
var image = SizedBox(
width: imageWidth,
height: imageHeight,
child: GestureDetector(
onTap: () => ImagePage.show(widget.illust.images[index].original),
child: AnimatedImage(
image: CachedImageProvider(widget.illust.images[index].medium),
width: imageWidth,
fit: BoxFit.cover,
height: imageHeight,
),
),
);
if (index == 0) {
return Hero(
tag: "illust_${widget.illust.id}",
child: image,
);
} else {
return image;
}
}
}
class _BottomBar extends StatefulWidget {
const _BottomBar(this.illust, this.height, this.width);
final Illust illust;
final double height;
final double width;
@override
State<_BottomBar> createState() => _BottomBarState();
}
class _BottomBarState extends State<_BottomBar> {
double? top;
double pageHeight = 0;
double widgetHeight = 48;
final key = GlobalKey();
double _width = 0;
@override
void initState() {
_width = widget.width;
pageHeight = widget.height;
top = pageHeight - _kBottomBarHeight;
Future.delayed(const Duration(milliseconds: 200), () {
final box = key.currentContext?.findRenderObject() as RenderBox?;
widgetHeight = (box?.size.height) ?? 0;
});
super.initState();
}
@override
void didUpdateWidget(covariant _BottomBar oldWidget) {
if (widget.height != pageHeight) {
setState(() {
pageHeight = widget.height;
top = pageHeight - _kBottomBarHeight;
});
}
if(_width != widget.width) {
_width = widget.width;
Future.microtask(() {
final box = key.currentContext?.findRenderObject() as RenderBox?;
var oldHeight = widgetHeight;
widgetHeight = (box?.size.height) ?? 0;
if(oldHeight != widgetHeight && top != pageHeight - _kBottomBarHeight) {
setState(() {
top = pageHeight - widgetHeight;
});
}
});
}
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return AnimatedPositioned(
top: top,
left: 0,
right: 0,
duration: const Duration(milliseconds: 180),
curve: Curves.ease,
child: Card(
borderRadius: const BorderRadius.vertical(top: Radius.circular(8)),
backgroundColor:
FluentTheme.of(context).micaBackgroundColor.withOpacity(0.96),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: SizedBox(
width: double.infinity,
key: key,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
buildTop(),
buildStats(),
buildTags(),
SelectableText("${"Artwork ID".tl}: ${widget.illust.id}\n${"Artist ID".tl}: ${widget.illust.author.id}", style: TextStyle(color: ColorScheme.of(context).outline),).paddingLeft(4),
const SizedBox(height: 8,)
],
),
),
),
);
}
Widget buildTop() {
return SizedBox(
height: _kBottomBarHeight,
width: double.infinity,
child: LayoutBuilder(builder: (context, constrains) {
return Row(
children: [
buildAuthor(),
...buildActions(constrains.maxWidth),
const Spacer(),
if (top == pageHeight - _kBottomBarHeight)
IconButton(
icon: const Icon(FluentIcons.up),
onPressed: () {
setState(() {
top = pageHeight - widgetHeight;
});
})
else
IconButton(
icon: const Icon(FluentIcons.down),
onPressed: () {
setState(() {
top = pageHeight - _kBottomBarHeight;
});
})
],
);
}),
);
}
bool isFollowing = false;
Widget buildAuthor() {
void follow() async{
if(isFollowing) return;
setState(() {
isFollowing = true;
});
var method = widget.illust.author.isFollowed ? "delete" : "add";
var res = await Network().follow(widget.illust.author.id.toString(), method);
if(res.error) {
if(mounted) {
context.showToast(message: "Network Error");
}
} else {
widget.illust.author.isFollowed = !widget.illust.author.isFollowed;
}
setState(() {
isFollowing = false;
});
}
return Card(
margin: const EdgeInsets.symmetric(vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 8),
borderRadius: BorderRadius.circular(8),
backgroundColor: FluentTheme.of(context).cardColor.withOpacity(0.72),
child: SizedBox(
height: double.infinity,
width: 246,
child: Row(
children: [
SizedBox(
height: 40,
width: 40,
child: ClipRRect(
borderRadius: BorderRadius.circular(40),
child: ColoredBox(
color: ColorScheme.of(context).secondaryContainer,
child: GestureDetector(
onTap: () => context.to(() =>
UserInfoPage(widget.illust.author.id.toString())),
child: AnimatedImage(
image: CachedImageProvider(widget.illust.author.avatar),
width: 40,
height: 40,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
),
),
),
),
),
const SizedBox(
width: 8,
),
Expanded(
child: Text(
widget.illust.author.name,
maxLines: 2,
),
),
if(isFollowing)
Button(onPressed: follow, child: const SizedBox(
width: 42,
height: 24,
child: Center(
child: SizedBox.square(
dimension: 18,
child: ProgressRing(strokeWidth: 2,),
),
),
))
else if (!widget.illust.author.isFollowed)
Button(onPressed: follow, child: Text("Follow".tl))
else
Button(
onPressed: follow,
child: Text("Unfollow".tl, style: TextStyle(color: ColorScheme.of(context).errorColor),),
),
],
),
),
);
}
bool isBookmarking = false;
Iterable<Widget> buildActions(double width) sync* {
yield const SizedBox(width: 8,);
void favorite() async{
if(isBookmarking) return;
setState(() {
isBookmarking = true;
});
var method = widget.illust.isBookmarked ? "delete" : "add";
var res = await Network().addBookmark(widget.illust.id.toString(), method);
if(res.error) {
if(mounted) {
context.showToast(message: "Network Error");
}
} else {
widget.illust.isBookmarked = !widget.illust.isBookmarked;
}
setState(() {
isBookmarking = false;
});
}
void download() {}
bool showText = width > 640;
yield Button(
onPressed: favorite,
child: SizedBox(
height: 28,
child: Row(
children: [
if(isBookmarking)
const SizedBox(
width: 18,
height: 18,
child: ProgressRing(strokeWidth: 2,),
)
else if(widget.illust.isBookmarked)
Icon(
Icons.favorite,
color: ColorScheme.of(context).errorColor,
size: 18,
)
else
const Icon(
Icons.favorite_border,
size: 18,
),
if(showText)
const SizedBox(width: 8,),
if(showText)
if(widget.illust.isBookmarked)
Text("Cancel".tl)
else
Text("Favorite".tl)
],
),
),
);
yield const SizedBox(width: 8,);
if (!widget.illust.downloaded) {
yield Button(
onPressed: download,
child: SizedBox(
height: 28,
child: Row(
children: [
const Icon(
FluentIcons.download,
size: 18,
),
if(showText)
const SizedBox(width: 8,),
if(showText)
Text("Download".tl),
],
),
),
);
}
yield const SizedBox(width: 8,);
yield Button(
onPressed: favorite,
child: SizedBox(
height: 28,
child: Row(
children: [
const Icon(
FluentIcons.comment,
size: 18,
),
if(showText)
const SizedBox(width: 8,),
if(showText)
Text("Comment".tl),
],
),
),
);
}
Widget buildStats(){
return SizedBox(
height: 56,
child: Row(
children: [
const SizedBox(width: 2,),
Expanded(
child: Container(
height: 52,
decoration: BoxDecoration(
border: Border.all(color: ColorScheme.of(context).outlineVariant, width: 0.6),
borderRadius: BorderRadius.circular(4)
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(FluentIcons.view, size: 20,),
Text("Views".tl, style: const TextStyle(fontSize: 12),)
],
),
const SizedBox(width: 12,),
Text(widget.illust.totalView.toString(), style: TextStyle(color: ColorScheme.of(context).primary, fontWeight: FontWeight.w500, fontSize: 18),)
],
),
),
),
const SizedBox(width: 16,),
Expanded(child: Container(
height: 52,
decoration: BoxDecoration(
border: Border.all(color: ColorScheme.of(context).outlineVariant, width: 0.6),
borderRadius: BorderRadius.circular(4)
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(FluentIcons.six_point_star, size: 20,),
Text("Favorites".tl, style: const TextStyle(fontSize: 12),)
],
),
const SizedBox(width: 12,),
Text(widget.illust.totalBookmarks.toString(), style: TextStyle(color: ColorScheme.of(context).primary, fontWeight: FontWeight.w500, fontSize: 18),)
],
),
)),
const SizedBox(width: 2,),
],
),
);
}
Widget buildTags() {
return SizedBox(
width: double.infinity,
child: Wrap(
spacing: 4,
runSpacing: 4,
children: widget.illust.tags.map((e) {
var text = e.name;
if(e.translatedName != null && e.name != e.translatedName) {
text += "/${e.translatedName}";
}
return Card(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
child: Text(text, style: const TextStyle(fontSize: 13),),
);
}).toList(),
),
).paddingVertical(8).paddingHorizontal(2);
}
}

90
lib/pages/image_page.dart Normal file
View File

@@ -0,0 +1,90 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:photo_view/photo_view.dart';
import 'package:pixes/components/page_route.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/pages/main_page.dart';
import 'package:window_manager/window_manager.dart';
class ImagePage extends StatefulWidget {
const ImagePage(this.url, {super.key});
final String url;
static show(String url) {
App.rootNavigatorKey.currentState?.push(
AppPageRoute(builder: (context) => ImagePage(url)));
}
@override
State<ImagePage> createState() => _ImagePageState();
}
class _ImagePageState extends State<ImagePage> with WindowListener{
int windowButtonKey = 0;
@override
void initState() {
windowManager.addListener(this);
super.initState();
}
@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
@override
void onWindowMaximize() {
setState(() {
windowButtonKey++;
});
}
@override
void onWindowUnmaximize() {
setState(() {
windowButtonKey++;
});
}
@override
Widget build(BuildContext context) {
return ColoredBox(
color: FluentTheme.of(context).micaBackgroundColor.withOpacity(1),
child: Stack(
children: [
Positioned.fill(child: PhotoView(
backgroundDecoration: const BoxDecoration(
color: Colors.transparent
),
filterQuality: FilterQuality.medium,
imageProvider: CachedImageProvider(widget.url),
)),
Positioned(
top: 0,
left: 0,
right: 0,
child: SizedBox(
height: 36,
child: Row(
children: [
const SizedBox(width: 6,),
IconButton(
icon: const Icon(FluentIcons.back).paddingAll(2),
onPressed: () => context.pop()
),
const Expanded(
child: DragToMoveArea(child: SizedBox.expand(),),
),
WindowButtons(key: ValueKey(windowButtonKey),),
],
),
),
),
],
),
);
}
}

218
lib/pages/login_page.dart Normal file
View File

@@ -0,0 +1,218 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/app_links.dart';
import 'package:pixes/utils/translation.dart';
import 'package:url_launcher/url_launcher_string.dart';
class LoginPage extends StatefulWidget {
const LoginPage(this.callback, {super.key});
final void Function() callback;
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
bool checked = false;
bool waitingForAuth = false;
bool isLogging = false;
@override
Widget build(BuildContext context) {
if (!waitingForAuth) {
return buildLogin(context);
} else {
return buildWaiting(context);
}
}
Widget buildLogin(BuildContext context) {
return SizedBox(
child: Center(
child: Card(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
child: SizedBox(
width: 300,
height: 300,
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Login".tl,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
),
Expanded(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (checked)
FilledButton(
onPressed: onContinue,
child: Text("Continue".tl),
)
else
Container(
height: 28,
width: 78,
decoration: BoxDecoration(
color: FluentTheme.of(context)
.inactiveBackgroundColor,
borderRadius: BorderRadius.circular(4)),
child: Center(
child: Text("Continue".tl),
),
),
const SizedBox(
height: 16,
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
child: Text(
"You need to complete the login operation in the browser window that will open."
.tl),
)
],
),
),
),
Row(
children: [
Checkbox(
checked: checked,
onChanged: (value) => setState(() {
checked = value ?? false;
})),
const SizedBox(
width: 8,
),
Text("I have read and agree to the Terms of Use".tl)
],
)
],
),
)),
),
);
}
Widget buildWaiting(BuildContext context) {
return SizedBox(
child: Center(
child: Card(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
child: SizedBox(
width: 300,
height: 300,
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Waiting...".tl,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
),
Expanded(
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
child: Text(
"Waiting for authentication. Please finished in the browser."
.tl),
),
),
),
Row(
children: [
Button(
child: Text("Back".tl),
onPressed: () {
setState(() {
waitingForAuth = false;
});
}),
const Spacer(),
],
)
],
),
)),
),
);
}
Widget buildLoading(BuildContext context) {
return SizedBox(
child: Center(
child: Card(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
child: SizedBox(
width: 300,
height: 300,
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Logging in".tl,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
),
const Expanded(
child: Center(
child: ProgressRing(),
),
),
],
),
)),
),
);
}
void onContinue() async {
var url = await Network().generateWebviewUrl();
launchUrlString(url);
onLink = (uri) {
if (uri.scheme == "pixiv") {
onFinished(uri.queryParameters["code"]!);
onLink = null;
return true;
}
return false;
};
setState(() {
waitingForAuth = true;
});
}
void onFinished(String code) async {
setState(() {
isLogging = true;
waitingForAuth = false;
});
var res = await Network().loginWithCode(code);
if (res.error) {
if(mounted) {
context.showToast(message: res.errorMessage!);
}
setState(() {
isLogging = false;
});
} else {
widget.callback();
}
}
}

619
lib/pages/main_page.dart Normal file
View File

@@ -0,0 +1,619 @@
import "dart:async";
import "package:fluent_ui/fluent_ui.dart";
import "package:pixes/appdata.dart";
import "package:pixes/components/color_scheme.dart";
import "package:pixes/components/md.dart";
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/recommendation_page.dart";
import "package:pixes/pages/login_page.dart";
import "package:pixes/pages/search_page.dart";
import "package:pixes/pages/settings_page.dart";
import "package:pixes/pages/user_info_page.dart";
import "package:pixes/utils/mouse_listener.dart";
import "package:pixes/utils/translation.dart";
import "package:window_manager/window_manager.dart";
import "../components/page_route.dart";
const _kAppBarHeight = 36.0;
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> with WindowListener {
final navigatorKey = GlobalKey<NavigatorState>();
int index = 1;
int windowButtonKey = 0;
@override
void initState() {
windowManager.addListener(this);
listenMouseSideButtonToBack(navigatorKey);
super.initState();
}
@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
@override
void onWindowMaximize() {
setState(() {
windowButtonKey++;
});
}
@override
void onWindowUnmaximize() {
setState(() {
windowButtonKey++;
});
}
bool get isLogin => Network().token != null;
@override
Widget build(BuildContext context) {
if (!isLogin) {
return NavigationView(
appBar: buildAppBar(context, navigatorKey),
content: LoginPage(() => setState(() {})),
);
}
return ColorScheme(
brightness: FluentTheme.of(context).brightness,
child: NavigationView(
appBar: buildAppBar(context, navigatorKey),
pane: NavigationPane(
selected: index,
onChanged: (value) {
setState(() {
index = value;
});
navigate(value);
},
items: [
UserPane(),
PaneItem(
icon: const Icon(MdIcons.search, size: 20,),
title: Text('Search'.tl),
body: const SizedBox.shrink(),
),
PaneItemHeader(header: Text("Artwork".tl).paddingVertical(4).paddingLeft(8)),
PaneItem(
icon: const Icon(MdIcons.star_border, size: 20,),
title: Text('Recommendations'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.bookmark_outline, size: 20),
title: Text('Bookmarks'.tl),
body: const SizedBox.shrink(),
),
PaneItemSeparator(),
PaneItem(
icon: const Icon(MdIcons.explore_outlined, size: 20),
title: Text('Explore'.tl),
body: const SizedBox.shrink(),
),
],
footerItems: [
PaneItem(
icon: const Icon(MdIcons.settings_outlined, size: 20),
title: Text('Settings'.tl),
body: const SizedBox.shrink(),
),
],
),
paneBodyBuilder: (pane, child) => Navigator(
key: navigatorKey,
onGenerateRoute: (settings) => AppPageRoute(
builder: (context) => const RecommendationPage()),
)));
}
static final pageBuilders = [
() => UserInfoPage(appdata.account!.user.id),
() => const SearchPage(),
() => const RecommendationPage(),
() => const BookMarkedArtworkPage(),
() => const ExplorePage(),
() => const SettingsPage(),
];
void navigate(int index) {
var page = pageBuilders.elementAtOrNull(index) ??
() => Center(
child: Text("Invalid Page: $index"),
);
navigatorKey.currentState!.pushAndRemoveUntil(
AppPageRoute(builder: (context) => page()), (route) => false);
}
NavigationAppBar buildAppBar(
BuildContext context, GlobalKey<NavigatorState> navigatorKey) {
return NavigationAppBar(
automaticallyImplyLeading: false,
height: _kAppBarHeight,
title: () {
if (!App.isDesktop) {
return const Align(
alignment: AlignmentDirectional.centerStart,
child: Text("pixes"),
);
}
return const DragToMoveArea(
child: Padding(
padding: EdgeInsets.only(bottom: 4),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
"Pixes",
style: TextStyle(fontSize: 13),
),
),
),
);
}(),
leading: _BackButton(navigatorKey),
actions: WindowButtons(
key: ValueKey(windowButtonKey),
),
);
}
}
class _BackButton extends StatefulWidget {
const _BackButton(this.navigatorKey);
final GlobalKey<NavigatorState> navigatorKey;
@override
State<_BackButton> createState() => _BackButtonState();
}
class _BackButtonState extends State<_BackButton> {
GlobalKey<NavigatorState> get navigatorKey => widget.navigatorKey;
bool enabled = false;
Timer? timer;
@override
void initState() {
enabled = navigatorKey.currentState?.canPop() == true;
loop();
super.initState();
}
void loop() {
timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
if(!mounted) {
timer.cancel();
} else {
bool enabled = navigatorKey.currentState?.canPop() == true;
if(enabled != this.enabled) {
setState(() {
this.enabled = enabled;
});
}
}
});
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
void onPressed() {
if (navigatorKey.currentState?.canPop() ?? false) {
navigatorKey.currentState?.pop();
}
}
return NavigationPaneTheme(
data: NavigationPaneTheme.of(context).merge(NavigationPaneThemeData(
unselectedIconColor: ButtonState.resolveWith((states) {
if (states.isDisabled) {
return ButtonThemeData.buttonColor(context, states);
}
return ButtonThemeData.uncheckedInputColor(
FluentTheme.of(context),
states,
).basedOnLuminance();
}),
)),
child: Builder(
builder: (context) => PaneItem(
icon: const Center(child: Icon(FluentIcons.back, size: 12.0)),
title: const Text("Back"),
body: const SizedBox.shrink(),
enabled: enabled,
).build(
context,
false,
onPressed,
displayMode: PaneDisplayMode.compact,
).paddingTop(2),
),
);
}
}
class WindowButtons extends StatelessWidget {
const WindowButtons({super.key});
@override
Widget build(BuildContext context) {
final FluentThemeData theme = FluentTheme.of(context);
final color = theme.iconTheme.color ?? Colors.black;
final hoverColor = theme.inactiveBackgroundColor;
return SizedBox(
width: 138,
height: _kAppBarHeight,
child: Row(
children: [
WindowButton(
icon: MinimizeIcon(color: color),
hoverColor: hoverColor,
onPressed: () async {
bool isMinimized = await windowManager.isMinimized();
if (isMinimized) {
windowManager.restore();
} else {
windowManager.minimize();
}
},
),
FutureBuilder<bool>(
future: windowManager.isMaximized(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.data == true) {
return WindowButton(
icon: RestoreIcon(
color: color,
),
hoverColor: hoverColor,
onPressed: () {
windowManager.unmaximize();
},
);
}
return WindowButton(
icon: MaximizeIcon(
color: color,
),
hoverColor: hoverColor,
onPressed: () {
windowManager.maximize();
},
);
},
),
WindowButton(
icon: CloseIcon(
color: color,
),
hoverIcon: CloseIcon(
color: theme.brightness == Brightness.light
? Colors.white
: Colors.black,
),
hoverColor: Colors.red,
onPressed: () {
windowManager.close();
},
),
],
),
);
}
}
class WindowButton extends StatefulWidget {
const WindowButton(
{required this.icon,
required this.onPressed,
required this.hoverColor,
this.hoverIcon,
super.key});
final Widget icon;
final void Function() onPressed;
final Color hoverColor;
final Widget? hoverIcon;
@override
State<WindowButton> createState() => _WindowButtonState();
}
class _WindowButtonState extends State<WindowButton> {
bool isHovering = false;
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (event) => setState(() {
isHovering = true;
}),
onExit: (event) => setState(() {
isHovering = false;
}),
child: GestureDetector(
onTap: widget.onPressed,
child: Container(
width: 46,
height: double.infinity,
decoration:
BoxDecoration(color: isHovering ? widget.hoverColor : null),
child: isHovering ? widget.hoverIcon ?? widget.icon : widget.icon,
),
),
);
}
}
class UserPane extends PaneItem {
UserPane() : super(icon: const SizedBox(), body: const SizedBox());
@override
Widget build(BuildContext context, bool selected, VoidCallback? onPressed,
{PaneDisplayMode? displayMode,
bool showTextOnTop = true,
int? itemIndex,
bool? autofocus}) {
final maybeBody = NavigationView.maybeOf(context);
var mode = displayMode ?? maybeBody?.displayMode ?? PaneDisplayMode.minimal;
if (maybeBody?.compactOverlayOpen == true) {
mode = PaneDisplayMode.open;
}
Widget body = () {
switch (mode) {
case PaneDisplayMode.minimal:
case PaneDisplayMode.open:
return LayoutBuilder(builder: (context, constrains) {
if (constrains.maxHeight < 72 || constrains.maxWidth < 120) {
return const SizedBox();
}
return Container(
width: double.infinity,
height: 64,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
child: Row(
children: [
Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(48),
child: Image(
height: 48,
width: 48,
image: NetworkImage(appdata.account!.user.profile),
fit: BoxFit.fill,
),
),
),
const SizedBox(
width: 8,
),
if (constrains.maxWidth > 90)
Expanded(
child: Center(
child: SizedBox(
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
appdata.account!.user.name,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.w500),
),
Text(
appdata.account!.user.email,
style: const TextStyle(fontSize: 12),
)
],
),
),
),
)
],
),
);
});
case PaneDisplayMode.compact:
case PaneDisplayMode.top:
return LayoutBuilder(builder: (context, constrains) {
if (constrains.maxHeight < 48 || constrains.maxWidth < 32) {
return const SizedBox();
}
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(32),
child: Image(
height: 30,
width: 30,
image: NetworkImage(appdata.account!.user.profile),
fit: BoxFit.fill,
),
).paddingAll(4),
);
});
default:
throw "Invalid Display mode";
}
}();
var button = HoverButton(
builder: (context, states) {
final theme = NavigationPaneTheme.of(context);
return Container(
margin: const EdgeInsets.symmetric(horizontal: 6.0),
decoration: BoxDecoration(
color: () {
final tileColor = this.tileColor ??
theme.tileColor ??
kDefaultPaneItemColor(context, mode == PaneDisplayMode.top);
final newStates = states.toSet()..remove(ButtonStates.disabled);
if (selected && selectedTileColor != null) {
return selectedTileColor!.resolve(newStates);
}
return tileColor.resolve(
selected
? {
states.isHovering
? ButtonStates.pressing
: ButtonStates.hovering,
}
: newStates,
);
}(),
borderRadius: BorderRadius.circular(4.0),
),
child: FocusBorder(
focused: states.isFocused,
renderOutside: false,
child: body,
),
);
},
onPressed: onPressed,
);
return Padding(
key: key,
padding: const EdgeInsetsDirectional.only(bottom: 4.0),
child: button,
);
}
}
/// Close
class CloseIcon extends StatelessWidget {
final Color color;
const CloseIcon({super.key, required this.color});
@override
Widget build(BuildContext context) => _AlignedPaint(_ClosePainter(color));
}
class _ClosePainter extends _IconPainter {
_ClosePainter(super.color);
@override
void paint(Canvas canvas, Size size) {
Paint p = getPaint(color, true);
canvas.drawLine(const Offset(0, 0), Offset(size.width, size.height), p);
canvas.drawLine(Offset(0, size.height), Offset(size.width, 0), p);
}
}
/// Maximize
class MaximizeIcon extends StatelessWidget {
final Color color;
const MaximizeIcon({super.key, required this.color});
@override
Widget build(BuildContext context) => _AlignedPaint(_MaximizePainter(color));
}
class _MaximizePainter extends _IconPainter {
_MaximizePainter(super.color);
@override
void paint(Canvas canvas, Size size) {
Paint p = getPaint(color);
canvas.drawRect(Rect.fromLTRB(0, 0, size.width - 1, size.height - 1), p);
}
}
/// Restore
class RestoreIcon extends StatelessWidget {
final Color color;
const RestoreIcon({
super.key,
required this.color,
});
@override
Widget build(BuildContext context) => _AlignedPaint(_RestorePainter(color));
}
class _RestorePainter extends _IconPainter {
_RestorePainter(super.color);
@override
void paint(Canvas canvas, Size size) {
Paint p = getPaint(color);
canvas.drawRect(Rect.fromLTRB(0, 2, size.width - 2, size.height), p);
canvas.drawLine(const Offset(2, 2), const Offset(2, 0), p);
canvas.drawLine(const Offset(2, 0), Offset(size.width, 0), p);
canvas.drawLine(
Offset(size.width, 0), Offset(size.width, size.height - 2), p);
canvas.drawLine(Offset(size.width, size.height - 2),
Offset(size.width - 2, size.height - 2), p);
}
}
/// Minimize
class MinimizeIcon extends StatelessWidget {
final Color color;
const MinimizeIcon({super.key, required this.color});
@override
Widget build(BuildContext context) => _AlignedPaint(_MinimizePainter(color));
}
class _MinimizePainter extends _IconPainter {
_MinimizePainter(super.color);
@override
void paint(Canvas canvas, Size size) {
Paint p = getPaint(color);
canvas.drawLine(
Offset(0, size.height / 2), Offset(size.width, size.height / 2), p);
}
}
/// Helpers
abstract class _IconPainter extends CustomPainter {
_IconPainter(this.color);
final Color color;
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
class _AlignedPaint extends StatelessWidget {
const _AlignedPaint(this.painter);
final CustomPainter painter;
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.center,
child: CustomPaint(size: const Size(10, 10), painter: painter));
}
}
Paint getPaint(Color color, [bool isAntiAlias = false]) => Paint()
..color = color
..style = PaintingStyle.stroke
..isAntiAlias = isAntiAlias
..strokeWidth = 1;

15
lib/pages/ranking.dart Normal file
View File

@@ -0,0 +1,15 @@
import 'package:fluent_ui/fluent_ui.dart';
class RankingPage extends StatefulWidget {
const RankingPage({super.key});
@override
State<RankingPage> createState() => _RankingPageState();
}
class _RankingPageState extends State<RankingPage> {
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}

View File

@@ -0,0 +1,38 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/components/illust_widget.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/network/res.dart';
class RecommendationPage extends StatefulWidget {
const RecommendationPage({super.key});
@override
State<RecommendationPage> createState() => _RecommendationPageState();
}
class _RecommendationPageState extends MultiPageLoadingState<RecommendationPage, 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]);
},
);
});
}
@override
Future<Res<List<Illust>>> loadData(page) {
return Network().getRecommendedIllusts();
}
}

238
lib/pages/search_page.dart Normal file
View File

@@ -0,0 +1,238 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/pages/user_info_page.dart';
import 'package:pixes/utils/translation.dart';
import '../components/animated_image.dart';
import '../components/color_scheme.dart';
import '../foundation/image_provider.dart';
class SearchPage extends StatefulWidget {
const SearchPage({super.key});
@override
State<SearchPage> createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> {
String text = "";
int searchType = 0;
void search() {
switch(searchType) {
case 0:
context.to(() => SearchResultPage(text));
case 1:
// TODO: artwork by id
throw UnimplementedError();
case 2:
context.to(() => UserInfoPage(text));
case 3:
// TODO: novel page
throw UnimplementedError();
}
}
@override
Widget build(BuildContext context) {
return ScaffoldPage(
content: Column(
children: [
buildSearchBar(),
const SizedBox(height: 8,),
const Expanded(
child: _TrendingTagsView(),
)
],
),
);
}
final optionController = FlyoutController();
Widget buildSearchBar() {
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: SizedBox(
height: 42,
width: double.infinity,
child: LayoutBuilder(
builder: (context, constrains) {
return SizedBox(
height: 42,
width: constrains.maxWidth,
child: Row(
children: [
Expanded(
child: TextBox(
placeholder: searchTypes[searchType].tl,
onChanged: (s) => text = s,
foregroundDecoration: BoxDecoration(
border: Border.all(
color: ColorScheme.of(context)
.outlineVariant
.withOpacity(0.6)),
borderRadius: BorderRadius.circular(4)),
suffix: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: search,
child: const Icon(
FluentIcons.search,
size: 16,
).paddingHorizontal(12),
),
),
),
),
const SizedBox(
width: 4,
),
FlyoutTarget(
controller: optionController,
child: Button(
child: const SizedBox(
height: 42,
child: Center(
child: Icon(FluentIcons.chevron_down),
),
),
onPressed: () {
optionController.showFlyout(
navigatorKey: App.rootNavigatorKey.currentState,
builder: buildSearchOption,
);
},
),
)
],
),
);
},
),
).paddingHorizontal(16),
);
}
static const searchTypes = [
"Keyword search",
"Artwork ID",
"Artist ID",
"Novel ID"
];
Widget buildSearchOption(BuildContext context) {
return MenuFlyout(
items: List.generate(
searchTypes.length,
(index) => MenuFlyoutItem(
text: Text(searchTypes[index].tl),
onPressed: () => setState(() => searchType = index))),
);
}
}
class _TrendingTagsView extends StatefulWidget {
const _TrendingTagsView();
@override
State<_TrendingTagsView> createState() => _TrendingTagsViewState();
}
class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<TrendingTag>> {
@override
Widget buildContent(BuildContext context, List<TrendingTag> data) {
return MasonryGridView.builder(
gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 240,
),
itemCount: data.length,
itemBuilder: (context, index) {
return buildItem(data[index]);
},
);
}
Widget buildItem(TrendingTag tag) {
final illust = tag.illust;
var text = tag.tag.name;
if(tag.tag.translatedName != null) {
text += "/${tag.tag.translatedName}";
}
return LayoutBuilder(builder: (context, constrains) {
final width = constrains.maxWidth;
final height = illust.height * width / illust.width;
return Container(
width: width,
height: height,
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
child: Card(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: (){
context.to(() => SearchResultPage(tag.tag.name));
},
child: Stack(
children: [
Positioned.fill(child: ClipRRect(
borderRadius: BorderRadius.circular(4.0),
child: AnimatedImage(
image: CachedImageProvider(illust.images.first.medium),
fit: BoxFit.cover,
width: width-16.0,
height: height-16.0,
),
)),
Positioned(
bottom: -2,
left: 0,
right: 0,
child: Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).micaBackgroundColor.withOpacity(0.84),
borderRadius: BorderRadius.circular(4)
),
child: Text(text).paddingHorizontal(4).paddingVertical(6).paddingBottom(2),
),
)
],
),
),
),
),
);
});
}
@override
Future<Res<List<TrendingTag>>> loadData() {
return Network().getHotTags();
}
}
class SearchResultPage extends StatefulWidget {
const SearchResultPage(this.keyword, {super.key});
final String keyword;
@override
State<SearchResultPage> createState() => _SearchResultPageState();
}
class _SearchResultPageState extends State<SearchResultPage> {
@override
Widget build(BuildContext context) {
return const ScaffoldPage();
}
}

View File

@@ -0,0 +1,15 @@
import 'package:fluent_ui/fluent_ui.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@override
State<SettingsPage> createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}

View File

@@ -0,0 +1,54 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/network/res.dart';
import 'package:pixes/utils/translation.dart';
class UserInfoPage extends StatefulWidget {
const UserInfoPage(this.id, {super.key});
final String id;
@override
State<UserInfoPage> createState() => _UserInfoPageState();
}
class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
@override
Widget buildContent(BuildContext context, UserDetails data) {
return SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 16),
ClipRRect(
borderRadius: BorderRadius.circular(64),
child: Image(
image: CachedImageProvider(data.avatar),
width: 64,
height: 64,
),
),
const SizedBox(height: 8),
Text(data.name, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
const SizedBox(height: 4),
Text.rich(
TextSpan(
children: [
TextSpan(text: 'Follows: '.tl),
TextSpan(text: '${data.totalFollowUsers}', style: const TextStyle(fontWeight: FontWeight.w500)),
],
),
style: const TextStyle(fontSize: 14),
),
],
),
);
}
@override
Future<Res<UserDetails>> loadData() {
return Network().getUserDetails(widget.id);
}
}