Whittle down to final one StatusAndRefreshButton implementation

merge-requests/67/merge
Hank Grabowski 2024-12-19 20:30:14 -05:00
rodzic 648d6e29dd
commit e3fc6adcaf
10 zmienionych plików z 11 dodań i 101 usunięć

Wyświetl plik

@ -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<bool> valueListenable;
final Future<void> 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<void> 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<void> Function() refreshFunction;
final Color? busyColor;
final Color? buttonColor;
const StatusAndRefreshButton3({
const StatusAndRefreshButton({
super.key,
required this.executing,
required this.refreshFunction,

Wyświetl plik

@ -177,7 +177,7 @@ class _CircleAddUsersScreenState extends ConsumerState<CircleAddUsersScreen> {
),
Padding(
padding: const EdgeInsets.all(8.0),
child: StatusAndRefreshButton3(
child: StatusAndRefreshButton(
executing: loading,
refreshFunction: () async => ref
.read(circlesProvider(profile).notifier)

Wyświetl plik

@ -229,7 +229,7 @@ class _CircleEditorScreenState extends ConsumerState<CircleEditorScreen> {
),
Padding(
padding: const EdgeInsets.all(8.0),
child: StatusAndRefreshButton3(
child: StatusAndRefreshButton(
executing: loading,
refreshFunction: () async => ref
.read(circlesProvider(profile).notifier)

Wyświetl plik

@ -126,7 +126,7 @@ class _ContactsScreenState extends ConsumerState<ContactsScreen> {
),
Padding(
padding: const EdgeInsets.all(8.0),
child: StatusAndRefreshButton3(
child: StatusAndRefreshButton(
executing: loading,
refreshFunction: () async {
if (loading) {

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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,

Wyświetl plik

@ -53,7 +53,7 @@ class _MessageThreadScreenState extends ConsumerState<MessageThreadScreen> {
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(

Wyświetl plik

@ -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)

Wyświetl plik

@ -38,7 +38,7 @@ class NotificationsScreen extends ConsumerWidget {
final actions = [
if (platformIsDesktop)
StatusAndRefreshButton3(
StatusAndRefreshButton(
executing: loading,
refreshFunction: () async => ref
.read(notificationsManagerProvider(profile).notifier)