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 Function() onPressed,
required BuildContext context,
required bool loading,
}) {
var theme = Theme.of(context);
return SafeArea(
@ -145,10 +146,17 @@ Widget _defaultButtonBuilder({
minimumSize: const Size(254, 50),
),
onPressed: onPressed,
child: Text(
title,
style: theme.textTheme.displayLarge,
),
child: loading
? Padding(
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 Function() onPressed,
required BuildContext context,
required bool loading,
});
typedef PostBuilder = Widget Function({

View file

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

View file

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

View file

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