From ddb73cf631e802efbf58147b8838d0b3d16e0de9 Mon Sep 17 00:00:00 2001 From: Jacques Date: Wed, 19 Feb 2025 10:06:40 +0100 Subject: [PATCH] fix: add loading indicator on creating post --- .../lib/src/models/timeline_options.dart | 17 +++++++++++++---- .../timeline_add_post_information_screen.dart | 1 + .../timeline_choose_category_screen.dart | 1 + .../lib/src/screens/timeline_post_overview.dart | 7 ++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/flutter_timeline/lib/src/models/timeline_options.dart b/packages/flutter_timeline/lib/src/models/timeline_options.dart index 4a6f4c7..8f518f8 100644 --- a/packages/flutter_timeline/lib/src/models/timeline_options.dart +++ b/packages/flutter_timeline/lib/src/models/timeline_options.dart @@ -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({ diff --git a/packages/flutter_timeline/lib/src/screens/timeline_add_post_information_screen.dart b/packages/flutter_timeline/lib/src/screens/timeline_add_post_information_screen.dart index 355cabc..377e0e3 100644 --- a/packages/flutter_timeline/lib/src/screens/timeline_add_post_information_screen.dart +++ b/packages/flutter_timeline/lib/src/screens/timeline_add_post_information_screen.dart @@ -195,6 +195,7 @@ class _TimelineAddPostInformationScreenState widget.onTapOverview(); }, context: context, + loading: false, ), ], ), diff --git a/packages/flutter_timeline/lib/src/screens/timeline_choose_category_screen.dart b/packages/flutter_timeline/lib/src/screens/timeline_choose_category_screen.dart index 717a702..f49144d 100644 --- a/packages/flutter_timeline/lib/src/screens/timeline_choose_category_screen.dart +++ b/packages/flutter_timeline/lib/src/screens/timeline_choose_category_screen.dart @@ -100,6 +100,7 @@ class TimelineChooseCategoryScreen extends StatelessWidget { if (context.mounted) Navigator.of(context).pop(); }, + loading: false, ), ), TextButton( diff --git a/packages/flutter_timeline/lib/src/screens/timeline_post_overview.dart b/packages/flutter_timeline/lib/src/screens/timeline_post_overview.dart index 0c93bda..7a37a0d 100644 --- a/packages/flutter_timeline/lib/src/screens/timeline_post_overview.dart +++ b/packages/flutter_timeline/lib/src/screens/timeline_post_overview.dart @@ -19,6 +19,7 @@ class TimelinePostOverview extends StatefulWidget { class _TimelinePostOverviewState extends State { bool isLoading = false; + @override Widget build(BuildContext context) { var currentPost = widget.timelineService.getCurrentPost(); @@ -59,12 +60,16 @@ class _TimelinePostOverviewState extends State { 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, ), ], ),