diff --git a/lib/controls/status_and_refresh_button.dart b/lib/controls/status_and_refresh_button.dart index c14b5e3..5585bb5 100644 --- a/lib/controls/status_and_refresh_button.dart +++ b/lib/controls/status_and_refresh_button.dart @@ -1,103 +1,13 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -// TODO Clean up down to one or two of these once refactoring complete -class StatusAndRefreshButton extends StatelessWidget { - final ValueListenable valueListenable; - final Future Function() refreshFunction; - final Color? busyColor; - final Color? buttonColor; - - const StatusAndRefreshButton({ - super.key, - required this.valueListenable, - required this.refreshFunction, - this.buttonColor, - this.busyColor, - }); - - @override - Widget build(BuildContext context) { - return ValueListenableBuilder( - valueListenable: valueListenable, - builder: (context2, executing, _) { - if (executing) { - final theme = Theme.of(context); - final size = theme.appBarTheme.actionsIconTheme?.size ?? - theme.iconTheme.size ?? - 24; - return Center( - child: SizedBox( - width: size, - height: size, - child: CircularProgressIndicator( - color: busyColor, - ), - ), - ); - } - return IconButton( - onPressed: refreshFunction, - icon: Icon( - Icons.refresh, - color: buttonColor, - )); - }); - } -} - -typedef WatcherFunction = bool Function(WidgetRef ref); - -class StatusAndRefreshButton2 extends ConsumerWidget { - final WatcherFunction watcher; - final Future Function() refreshFunction; - final Color? busyColor; - final Color? buttonColor; - - const StatusAndRefreshButton2({ - super.key, - required this.watcher, - required this.refreshFunction, - this.buttonColor, - this.busyColor, - }); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final executing = watcher(ref); - if (executing) { - final theme = Theme.of(context); - final size = theme.appBarTheme.actionsIconTheme?.size ?? - theme.iconTheme.size ?? - 24; - return Center( - child: SizedBox( - width: size, - height: size, - child: CircularProgressIndicator( - color: busyColor, - ), - ), - ); - } - - return IconButton( - onPressed: refreshFunction, - icon: Icon( - Icons.refresh, - color: buttonColor, - )); - } -} - -class StatusAndRefreshButton3 extends ConsumerWidget { +class StatusAndRefreshButton extends ConsumerWidget { final bool executing; final Future Function() refreshFunction; final Color? busyColor; final Color? buttonColor; - const StatusAndRefreshButton3({ + const StatusAndRefreshButton({ super.key, required this.executing, required this.refreshFunction, diff --git a/lib/screens/circle_add_users_screen.dart b/lib/screens/circle_add_users_screen.dart index eef294a..75a5bd6 100644 --- a/lib/screens/circle_add_users_screen.dart +++ b/lib/screens/circle_add_users_screen.dart @@ -177,7 +177,7 @@ class _CircleAddUsersScreenState extends ConsumerState { ), Padding( padding: const EdgeInsets.all(8.0), - child: StatusAndRefreshButton3( + child: StatusAndRefreshButton( executing: loading, refreshFunction: () async => ref .read(circlesProvider(profile).notifier) diff --git a/lib/screens/circle_editor_screen.dart b/lib/screens/circle_editor_screen.dart index bb429f5..722b351 100644 --- a/lib/screens/circle_editor_screen.dart +++ b/lib/screens/circle_editor_screen.dart @@ -229,7 +229,7 @@ class _CircleEditorScreenState extends ConsumerState { ), Padding( padding: const EdgeInsets.all(8.0), - child: StatusAndRefreshButton3( + child: StatusAndRefreshButton( executing: loading, refreshFunction: () async => ref .read(circlesProvider(profile).notifier) diff --git a/lib/screens/contacts_screen.dart b/lib/screens/contacts_screen.dart index 0cd50d9..df88d59 100644 --- a/lib/screens/contacts_screen.dart +++ b/lib/screens/contacts_screen.dart @@ -126,7 +126,7 @@ class _ContactsScreenState extends ConsumerState { ), Padding( padding: const EdgeInsets.all(8.0), - child: StatusAndRefreshButton3( + child: StatusAndRefreshButton( executing: loading, refreshFunction: () async { if (loading) { diff --git a/lib/screens/gallery_browsers_screen.dart b/lib/screens/gallery_browsers_screen.dart index e618ff4..482ac65 100644 --- a/lib/screens/gallery_browsers_screen.dart +++ b/lib/screens/gallery_browsers_screen.dart @@ -95,7 +95,7 @@ class GalleryBrowsersScreen extends ConsumerWidget { }; return Scaffold( appBar: StandardAppBar.build(context, 'Galleries', actions: [ - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => await ref .read(galleryListProvider(profile).notifier) diff --git a/lib/screens/gallery_screen.dart b/lib/screens/gallery_screen.dart index 7d7d0f0..ff988ee 100644 --- a/lib/screens/gallery_screen.dart +++ b/lib/screens/gallery_screen.dart @@ -34,7 +34,7 @@ class GalleryScreen extends ConsumerWidget { }; return Scaffold( appBar: StandardAppBar.build(context, galleryName, actions: [ - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => ref .read(galleryImagesProvider(profile, galleryName).notifier) diff --git a/lib/screens/interactions_viewer_screen.dart b/lib/screens/interactions_viewer_screen.dart index ad237b2..bb8ae0a 100644 --- a/lib/screens/interactions_viewer_screen.dart +++ b/lib/screens/interactions_viewer_screen.dart @@ -51,7 +51,7 @@ class InteractionsViewerScreen extends ConsumerWidget { return Scaffold( appBar: StandardAppBar.build(context, buildTitle(), actions: [ - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => refreshInteractors(ref, profile), busyColor: Theme.of(context).colorScheme.surface, diff --git a/lib/screens/message_thread_screen.dart b/lib/screens/message_thread_screen.dart index b5a8bfc..ee61eb1 100644 --- a/lib/screens/message_thread_screen.dart +++ b/lib/screens/message_thread_screen.dart @@ -53,7 +53,7 @@ class _MessageThreadScreenState extends ConsumerState { final title = thread.title.isEmpty ? 'Thread' : thread.title; return Scaffold( appBar: StandardAppBar.build(context, title, actions: [ - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => await ref .read(directMessageThreadServiceProvider( diff --git a/lib/screens/message_threads_browser_screen.dart b/lib/screens/message_threads_browser_screen.dart index c288ace..5f03b06 100644 --- a/lib/screens/message_threads_browser_screen.dart +++ b/lib/screens/message_threads_browser_screen.dart @@ -25,7 +25,7 @@ class MessagesScreen extends ConsumerWidget { return Scaffold( appBar: StandardAppBar.build(context, 'Direct Message Threads', actions: [ - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => await ref .read(directMessageThreadIdsProvider(profile).notifier) diff --git a/lib/screens/notifications_screen.dart b/lib/screens/notifications_screen.dart index e009cdd..6b697f4 100644 --- a/lib/screens/notifications_screen.dart +++ b/lib/screens/notifications_screen.dart @@ -38,7 +38,7 @@ class NotificationsScreen extends ConsumerWidget { final actions = [ if (platformIsDesktop) - StatusAndRefreshButton3( + StatusAndRefreshButton( executing: loading, refreshFunction: () async => ref .read(notificationsManagerProvider(profile).notifier)