fix: add loading indicator on creating post

This commit is contained in:
Jacques 2025-02-19 10:06:40 +01:00
parent 6273a9e686
commit ddb73cf631
4 changed files with 21 additions and 5 deletions

View file

@ -134,6 +134,7 @@ Widget _defaultButtonBuilder({
required String title, required String title,
required Function() onPressed, required Function() onPressed,
required BuildContext context, required BuildContext context,
required bool loading,
}) { }) {
var theme = Theme.of(context); var theme = Theme.of(context);
return SafeArea( return SafeArea(
@ -145,10 +146,17 @@ Widget _defaultButtonBuilder({
minimumSize: const Size(254, 50), minimumSize: const Size(254, 50),
), ),
onPressed: onPressed, onPressed: onPressed,
child: Text( child: loading
title, ? Padding(
style: theme.textTheme.displayLarge, padding: const EdgeInsets.symmetric(vertical: 8),
), child: CircularProgressIndicator(
color: theme.textTheme.displayLarge?.color,
),
)
: Text(
title,
style: theme.textTheme.displayLarge,
),
), ),
), ),
); );
@ -179,6 +187,7 @@ typedef ButtonBuilder = Widget Function({
required String title, required String title,
required Function() onPressed, required Function() onPressed,
required BuildContext context, required BuildContext context,
required bool loading,
}); });
typedef PostBuilder = Widget Function({ typedef PostBuilder = Widget Function({

View file

@ -195,6 +195,7 @@ class _TimelineAddPostInformationScreenState
widget.onTapOverview(); widget.onTapOverview();
}, },
context: context, context: context,
loading: false,
), ),
], ],
), ),

View file

@ -100,6 +100,7 @@ class TimelineChooseCategoryScreen extends StatelessWidget {
if (context.mounted) if (context.mounted)
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
loading: false,
), ),
), ),
TextButton( TextButton(

View file

@ -19,6 +19,7 @@ class TimelinePostOverview extends StatefulWidget {
class _TimelinePostOverviewState extends State<TimelinePostOverview> { class _TimelinePostOverviewState extends State<TimelinePostOverview> {
bool isLoading = false; bool isLoading = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var currentPost = widget.timelineService.getCurrentPost(); var currentPost = widget.timelineService.getCurrentPost();
@ -59,12 +60,16 @@ class _TimelinePostOverviewState extends State<TimelinePostOverview> {
title: widget.options.translations.postButtonTitle, title: widget.options.translations.postButtonTitle,
onPressed: () async { onPressed: () async {
if (isLoading) return; if (isLoading) return;
isLoading = true; setState(() {
isLoading = true;
});
await widget.timelineService.createPost(currentPost); await widget.timelineService.createPost(currentPost);
widget.options.onCreatePost?.call(currentPost); widget.options.onCreatePost?.call(currentPost);
widget.onTapCreatePost(currentPost); widget.onTapCreatePost(currentPost);
}, },
context: context, context: context,
loading: isLoading,
), ),
], ],
), ),