mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
follow in user info page
This commit is contained in:
@@ -70,7 +70,11 @@ class _UserPreviewWidgetState extends State<UserPreviewWidget> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Button(
|
Button(
|
||||||
onPressed: () => context.to(() => UserInfoPage(widget.user.id.toString())),
|
onPressed: () => context.to(() => UserInfoPage(widget.user.id.toString(), followCallback: (v){
|
||||||
|
setState(() {
|
||||||
|
widget.user.isFollowed = v;
|
||||||
|
});
|
||||||
|
},)),
|
||||||
child: Text("View".tl,),
|
child: Text("View".tl,),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8,),
|
const SizedBox(width: 8,),
|
||||||
|
@@ -54,7 +54,7 @@ class UserDetails {
|
|||||||
final String account;
|
final String account;
|
||||||
final String avatar;
|
final String avatar;
|
||||||
final String comment;
|
final String comment;
|
||||||
final bool isFollowed;
|
bool isFollowed;
|
||||||
final bool isBlocking;
|
final bool isBlocking;
|
||||||
final String? webpage;
|
final String? webpage;
|
||||||
final String gender;
|
final String gender;
|
||||||
|
@@ -268,7 +268,11 @@ class _BottomBarState extends State<_BottomBar> {
|
|||||||
color: ColorScheme.of(context).secondaryContainer,
|
color: ColorScheme.of(context).secondaryContainer,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => context.to(() =>
|
onTap: () => context.to(() =>
|
||||||
UserInfoPage(widget.illust.author.id.toString())),
|
UserInfoPage(
|
||||||
|
widget.illust.author.id.toString(),
|
||||||
|
followCallback: (b) => setState(() {
|
||||||
|
widget.illust.author.isFollowed = b;
|
||||||
|
}),)),
|
||||||
child: AnimatedImage(
|
child: AnimatedImage(
|
||||||
image: CachedImageProvider(widget.illust.author.avatar),
|
image: CachedImageProvider(widget.illust.author.avatar),
|
||||||
width: 40,
|
width: 40,
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
|
import 'package:pixes/appdata.dart';
|
||||||
import 'package:pixes/components/loading.dart';
|
import 'package:pixes/components/loading.dart';
|
||||||
import 'package:pixes/components/md.dart';
|
import 'package:pixes/components/md.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
@@ -13,10 +14,12 @@ import 'package:url_launcher/url_launcher_string.dart';
|
|||||||
import '../components/illust_widget.dart';
|
import '../components/illust_widget.dart';
|
||||||
|
|
||||||
class UserInfoPage extends StatefulWidget {
|
class UserInfoPage extends StatefulWidget {
|
||||||
const UserInfoPage(this.id, {super.key});
|
const UserInfoPage(this.id, {this.followCallback, super.key});
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
final void Function(bool)? followCallback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<UserInfoPage> createState() => _UserInfoPageState();
|
State<UserInfoPage> createState() => _UserInfoPageState();
|
||||||
}
|
}
|
||||||
@@ -36,6 +39,28 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isFollowing = false;
|
||||||
|
|
||||||
|
void follow() async{
|
||||||
|
if(isFollowing) return;
|
||||||
|
setState(() {
|
||||||
|
isFollowing = true;
|
||||||
|
});
|
||||||
|
var method = data!.isFollowed ? "delete" : "add";
|
||||||
|
var res = await Network().follow(data!.id.toString(), method);
|
||||||
|
if(res.error) {
|
||||||
|
if(mounted) {
|
||||||
|
context.showToast(message: "Network Error");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data!.isFollowed = !data!.isFollowed;
|
||||||
|
widget.followCallback?.call(data!.isFollowed);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
isFollowing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildUser() {
|
Widget buildUser() {
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -71,6 +96,27 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
),
|
),
|
||||||
style: const TextStyle(fontSize: 14),
|
style: const TextStyle(fontSize: 14),
|
||||||
),
|
),
|
||||||
|
if(widget.id != appdata.account?.user.id)
|
||||||
|
const SizedBox(height: 8,),
|
||||||
|
if(widget.id != appdata.account?.user.id)
|
||||||
|
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 (!data!.isFollowed)
|
||||||
|
Button(onPressed: follow, child: Text("Follow".tl))
|
||||||
|
else
|
||||||
|
Button(
|
||||||
|
onPressed: follow,
|
||||||
|
child: Text("Unfollow".tl, style: TextStyle(color: ColorScheme.of(context).error),),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -105,7 +151,7 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
buildHeader("Infomation".tl),
|
buildHeader("Information".tl),
|
||||||
buildItem(icon: MdIcons.comment_outlined, title: "Introduction".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.cake_outlined, title: "Birthday".tl, content: data!.birth),
|
||||||
buildItem(icon: MdIcons.location_city_outlined, title: "Region", content: data!.region),
|
buildItem(icon: MdIcons.location_city_outlined, title: "Region", content: data!.region),
|
||||||
|
Reference in New Issue
Block a user