♿ Optimize and fixes
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/account.dart';
|
||||
import 'package:solian/providers/account_status.dart';
|
||||
import 'package:solian/router.dart';
|
||||
@ -18,23 +17,38 @@ class AccountProfilePopup extends StatefulWidget {
|
||||
|
||||
class _AccountProfilePopupState extends State<AccountProfilePopup> {
|
||||
bool _isBusy = true;
|
||||
dynamic _hasError;
|
||||
|
||||
Account? _userinfo;
|
||||
|
||||
void _getUserinfo() async {
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
final client = ServiceFinder.configureClient('auth');
|
||||
final resp = await client.get('/users/${widget.name}');
|
||||
if (resp.statusCode == 200) {
|
||||
_userinfo = Account.fromJson(resp.body);
|
||||
setState(() => _isBusy = false);
|
||||
} else {
|
||||
context.showErrorDialog(resp.bodyString);
|
||||
Navigator.pop(context);
|
||||
try {
|
||||
final client = ServiceFinder.configureClient('auth');
|
||||
final resp = await client.get('/users/${widget.name}');
|
||||
if (resp.statusCode == 200) {
|
||||
setState(() {
|
||||
_userinfo = Account.fromJson(resp.body);
|
||||
_isBusy = false;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_hasError = resp.bodyString;
|
||||
_isBusy = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_hasError = e;
|
||||
_isBusy = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Color get _unFocusColor =>
|
||||
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -43,13 +57,35 @@ class _AccountProfilePopupState extends State<AccountProfilePopup> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isBusy || _userinfo == null) {
|
||||
if (_isBusy) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.75,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
if (_hasError != null) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.75,
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.cancel, size: 24),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
_hasError.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: _unFocusColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.75,
|
||||
child: Column(
|
||||
|
@ -97,13 +97,13 @@ class _PostActionState extends State<PostAction> {
|
||||
leading: const FaIcon(FontAwesomeIcons.reply, size: 20),
|
||||
title: Text('reply'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(reply: widget.item),
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(reply: widget.item),
|
||||
),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (!widget.noReact)
|
||||
@ -112,13 +112,13 @@ class _PostActionState extends State<PostAction> {
|
||||
leading: const FaIcon(FontAwesomeIcons.retweet, size: 20),
|
||||
title: Text('repost'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(repost: widget.item),
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(repost: widget.item),
|
||||
),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_canModifyContent && !widget.noReact)
|
||||
@ -146,13 +146,13 @@ class _PostActionState extends State<PostAction> {
|
||||
leading: const Icon(Icons.edit),
|
||||
title: Text('edit'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(edit: widget.item),
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(edit: widget.item),
|
||||
),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_canModifyContent)
|
||||
|
@ -85,7 +85,13 @@ class PostListEntryWidget extends StatelessWidget {
|
||||
context: context,
|
||||
builder: (context) => PostAction(item: item),
|
||||
).then((value) {
|
||||
if (value != null) onUpdate();
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
onUpdate();
|
||||
});
|
||||
} else if (value != null) {
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -9,6 +9,7 @@ class PostWarpedListWidget extends StatelessWidget {
|
||||
final bool isNestedClickable;
|
||||
final bool isPinned;
|
||||
final PagingController<int, Post> controller;
|
||||
final Function? onUpdate;
|
||||
|
||||
const PostWarpedListWidget({
|
||||
super.key,
|
||||
@ -17,6 +18,7 @@ class PostWarpedListWidget extends StatelessWidget {
|
||||
this.isClickable = true,
|
||||
this.isNestedClickable = true,
|
||||
this.isPinned = true,
|
||||
this.onUpdate,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -35,9 +37,7 @@ class PostWarpedListWidget extends StatelessWidget {
|
||||
isNestedClickable: isNestedClickable,
|
||||
isClickable: isClickable,
|
||||
item: item,
|
||||
onUpdate: () {
|
||||
controller.refresh();
|
||||
},
|
||||
onUpdate: onUpdate ?? () {},
|
||||
);
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user