♿ Optimize and fixes
This commit is contained in:
parent
12102bf527
commit
a157596a2e
@ -104,7 +104,6 @@ abstract class AppRouter {
|
||||
reply: arguments?.reply,
|
||||
repost: arguments?.repost,
|
||||
realm: arguments?.realm,
|
||||
postListController: arguments?.postListController,
|
||||
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
|
||||
),
|
||||
transitionsBuilder:
|
||||
|
@ -300,6 +300,7 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
||||
PostWarpedListWidget(
|
||||
isPinned: false,
|
||||
controller: _postController.pagingController,
|
||||
onUpdate: () => _postController.reloadAllOver(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
@ -87,7 +87,13 @@ class _DraftBoxScreenState extends State<DraftBoxScreen> {
|
||||
noReact: true,
|
||||
),
|
||||
).then((value) {
|
||||
if (value != null) _pagingController.refresh();
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
_pagingController.refresh();
|
||||
});
|
||||
} else if (value != null) {
|
||||
_pagingController.refresh();
|
||||
}
|
||||
});
|
||||
},
|
||||
).paddingOnly(left: 12, right: 12, bottom: 4);
|
||||
|
@ -77,7 +77,10 @@ class _FeedSearchScreenState extends State<FeedSearchScreen> {
|
||||
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
PostWarpedListWidget(controller: _pagingController),
|
||||
PostWarpedListWidget(
|
||||
controller: _pagingController,
|
||||
onUpdate: () => _pagingController.refresh(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -4,7 +4,6 @@ import 'package:solian/controllers/post_list_controller.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/screens/account/notification.dart';
|
||||
import 'package:solian/screens/posts/post_editor.dart';
|
||||
import 'package:solian/theme.dart';
|
||||
import 'package:solian/widgets/app_bar_title.dart';
|
||||
import 'package:solian/widgets/current_state_action.dart';
|
||||
@ -47,15 +46,20 @@ class _HomeScreenState extends State<HomeScreen>
|
||||
child: Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
onPressed: () async {
|
||||
final value = await showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => PostCreatePopup(
|
||||
controller: _postController,
|
||||
),
|
||||
builder: (context) => const PostCreatePopup(),
|
||||
);
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
_postController.reloadAllOver();
|
||||
});
|
||||
} else if (value != null) {
|
||||
_postController.reloadAllOver();
|
||||
}
|
||||
},
|
||||
),
|
||||
body: NestedScrollView(
|
||||
@ -100,6 +104,7 @@ class _HomeScreenState extends State<HomeScreen>
|
||||
child: CustomScrollView(slivers: [
|
||||
PostWarpedListWidget(
|
||||
controller: _postController.pagingController,
|
||||
onUpdate: () => _postController.reloadAllOver(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
@ -121,12 +126,10 @@ class _HomeScreenState extends State<HomeScreen>
|
||||
|
||||
class PostCreatePopup extends StatelessWidget {
|
||||
final bool hideDraftBox;
|
||||
final PostListController controller;
|
||||
|
||||
const PostCreatePopup({
|
||||
super.key,
|
||||
this.hideDraftBox = false,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -142,13 +145,14 @@ class PostCreatePopup extends StatelessWidget {
|
||||
icon: const Icon(Icons.post_add),
|
||||
label: 'postEditorModeStory'.tr,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(postListController: controller),
|
||||
queryParameters: {
|
||||
'mode': 0.toString(),
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -156,13 +160,14 @@ class PostCreatePopup extends StatelessWidget {
|
||||
icon: const Icon(Icons.description),
|
||||
label: 'postEditorModeArticle'.tr,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(postListController: controller),
|
||||
queryParameters: {
|
||||
'mode': 1.toString(),
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -170,8 +175,10 @@ class PostCreatePopup extends StatelessWidget {
|
||||
icon: const Icon(Icons.drafts),
|
||||
label: 'draftBoxOpen'.tr,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
AppRouter.instance.pushNamed('draftBox');
|
||||
Navigator.pop(
|
||||
context,
|
||||
AppRouter.instance.pushNamed('draftBox'),
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
|
@ -5,7 +5,6 @@ import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:markdown_toolbar/markdown_toolbar.dart';
|
||||
import 'package:solian/controllers/post_editor_controller.dart';
|
||||
import 'package:solian/controllers/post_list_controller.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/models/realm.dart';
|
||||
@ -23,14 +22,12 @@ class PostPublishArguments {
|
||||
final Post? reply;
|
||||
final Post? repost;
|
||||
final Realm? realm;
|
||||
final PostListController? postListController;
|
||||
|
||||
PostPublishArguments({
|
||||
this.edit,
|
||||
this.reply,
|
||||
this.repost,
|
||||
this.realm,
|
||||
this.postListController,
|
||||
});
|
||||
}
|
||||
|
||||
@ -39,7 +36,6 @@ class PostPublishScreen extends StatefulWidget {
|
||||
final Post? reply;
|
||||
final Post? repost;
|
||||
final Realm? realm;
|
||||
final PostListController? postListController;
|
||||
final int mode;
|
||||
|
||||
const PostPublishScreen({
|
||||
@ -48,7 +44,6 @@ class PostPublishScreen extends StatefulWidget {
|
||||
this.reply,
|
||||
this.repost,
|
||||
this.realm,
|
||||
this.postListController,
|
||||
required this.mode,
|
||||
});
|
||||
|
||||
@ -95,9 +90,6 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
|
||||
context.showErrorDialog(resp.bodyString);
|
||||
} else {
|
||||
_editorController.localClear();
|
||||
if (widget.postListController != null) {
|
||||
widget.postListController!.reloadAllOver();
|
||||
}
|
||||
AppRouter.instance.pop(resp.body);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
try {
|
||||
final client = ServiceFinder.configureClient('auth');
|
||||
final resp = await client.get('/users/${widget.name}');
|
||||
if (resp.statusCode == 200) {
|
||||
setState(() {
|
||||
_userinfo = Account.fromJson(resp.body);
|
||||
setState(() => _isBusy = false);
|
||||
_isBusy = false;
|
||||
});
|
||||
} else {
|
||||
context.showErrorDialog(resp.bodyString);
|
||||
Navigator.pop(context);
|
||||
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(
|
||||
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(
|
||||
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(
|
||||
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 ?? () {},
|
||||
);
|
||||
},
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user