Replace ValueListenableBuilders throughout with new StatusAndRefreshButton

merge-requests/67/merge
Hank Grabowski 2023-01-30 18:14:25 -05:00
rodzic 079b54b719
commit 7f46b72c51
6 zmienionych plików z 81 dodań i 129 usunięć

Wyświetl plik

@ -0,0 +1,46 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
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,
));
});
}
}

Wyświetl plik

@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../controls/padding.dart'; import '../controls/padding.dart';
import '../controls/standard_appbar.dart'; import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../globals.dart'; import '../globals.dart';
import '../services/gallery_service.dart'; import '../services/gallery_service.dart';
import '../services/network_status_service.dart'; import '../services/network_status_service.dart';
@ -19,29 +20,11 @@ class GalleryBrowsersScreen extends StatelessWidget {
final nss = getIt<NetworkStatusService>(); final nss = getIt<NetworkStatusService>();
return Scaffold( return Scaffold(
appBar: StandardAppBar.build(context, 'Galleries', actions: [ appBar: StandardAppBar.build(context, 'Galleries', actions: [
ValueListenableBuilder( StatusAndRefreshButton(
valueListenable: nss.imageGalleryLoadingStatus, valueListenable: nss.imageGalleryLoadingStatus,
builder: (context2, executing, _) { refreshFunction: () async => await service.updateGalleries(),
if (executing) { busyColor: Theme.of(context).colorScheme.background,
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: Theme.of(context).canvasColor),
),
);
}
return IconButton(
onPressed: () async => await service.updateGalleries(),
icon: Icon(
Icons.refresh,
));
}),
]), ]),
body: RefreshIndicator( body: RefreshIndicator(
onRefresh: () async { onRefresh: () async {

Wyświetl plik

@ -4,6 +4,7 @@ import 'package:logging/logging.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../controls/standard_appbar.dart'; import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../globals.dart'; import '../globals.dart';
import '../serializers/friendica/image_entry_friendica_extensions.dart'; import '../serializers/friendica/image_entry_friendica_extensions.dart';
import '../services/gallery_service.dart'; import '../services/gallery_service.dart';
@ -29,33 +30,15 @@ class GalleryScreen extends StatelessWidget {
); );
return Scaffold( return Scaffold(
appBar: StandardAppBar.build(context, galleryName, actions: [ appBar: StandardAppBar.build(context, galleryName, actions: [
ValueListenableBuilder( StatusAndRefreshButton(
valueListenable: nss.imageGalleryLoadingStatus, valueListenable: nss.imageGalleryLoadingStatus,
builder: (context2, executing, _) { refreshFunction: () async => await service.updateGalleryImageList(
if (executing) { galleryName: galleryName,
final theme = Theme.of(context); withNextPage: false,
final size = theme.appBarTheme.actionsIconTheme?.size ?? nextPageOnly: false,
theme.iconTheme.size ?? ),
24; busyColor: Theme.of(context).appBarTheme.foregroundColor,
return Center( ),
child: SizedBox(
width: size,
height: size,
child: CircularProgressIndicator(
color: Theme.of(context).canvasColor),
),
);
}
return IconButton(
onPressed: () async => await service.updateGalleryImageList(
galleryName: galleryName,
withNextPage: false,
nextPageOnly: false,
),
icon: Icon(
Icons.refresh,
));
}),
]), ]),
body: body, body: body,
); );

Wyświetl plik

@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../controls/app_bottom_nav_bar.dart'; import '../controls/app_bottom_nav_bar.dart';
import '../controls/padding.dart'; import '../controls/padding.dart';
import '../controls/status_and_refresh_button.dart';
import '../controls/timeline/timeline_panel.dart'; import '../controls/timeline/timeline_panel.dart';
import '../globals.dart'; import '../globals.dart';
import '../models/TimelineIdentifiers.dart'; import '../models/TimelineIdentifiers.dart';
@ -81,30 +82,12 @@ class _HomeScreenState extends State<HomeScreen> {
], ],
), ),
actions: [ actions: [
ValueListenableBuilder( StatusAndRefreshButton(
valueListenable: nss.timelineLoadingStatus, valueListenable: nss.timelineLoadingStatus,
builder: (context2, executing, _) { refreshFunction: () async => await manager.updateTimeline(
if (executing) { currentTimeline, TimelineRefreshType.refresh),
final theme = Theme.of(context); buttonColor: Theme.of(context).textTheme.bodyLarge?.color,
final size = theme.appBarTheme.actionsIconTheme?.size ?? ),
theme.iconTheme.size ??
24;
return Center(
child: SizedBox(
width: size,
height: size,
child: const CircularProgressIndicator(),
),
);
}
return IconButton(
onPressed: () async => await manager.updateTimeline(
currentTimeline, TimelineRefreshType.refresh),
icon: Icon(
Icons.refresh,
color: Theme.of(context).textTheme.bodyLarge?.color,
));
}),
IconButton( IconButton(
onPressed: () { onPressed: () {
context.push('/post/new'); context.push('/post/new');

Wyświetl plik

@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../controls/app_bottom_nav_bar.dart'; import '../controls/app_bottom_nav_bar.dart';
import '../controls/notifications_control.dart'; import '../controls/notifications_control.dart';
import '../controls/standard_appbar.dart'; import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../globals.dart'; import '../globals.dart';
import '../services/network_status_service.dart'; import '../services/network_status_service.dart';
import '../services/notifications_manager.dart'; import '../services/notifications_manager.dart';
@ -53,28 +54,11 @@ class NotificationsScreen extends StatelessWidget {
context, context,
title, title,
actions: [ actions: [
ValueListenableBuilder( StatusAndRefreshButton(
valueListenable: nss.notificationsUpdateStatus, valueListenable: nss.notificationsUpdateStatus,
builder: (context2, executing, _) { refreshFunction: () async => manager.updateNotifications(),
if (executing) { busyColor: Theme.of(context).colorScheme.background,
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: theme.canvasColor,
),
),
);
}
return IconButton(
onPressed: () async => await manager.updateNotifications(),
icon: const Icon(Icons.refresh));
}),
IconButton( IconButton(
onPressed: () async => _clearAllNotifications(context, manager), onPressed: () async => _clearAllNotifications(context, manager),
icon: const Icon(Icons.cleaning_services), icon: const Icon(Icons.cleaning_services),

Wyświetl plik

@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../controls/standard_appbar.dart'; import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../controls/timeline/timeline_panel.dart'; import '../controls/timeline/timeline_panel.dart';
import '../globals.dart'; import '../globals.dart';
import '../models/TimelineIdentifiers.dart'; import '../models/TimelineIdentifiers.dart';
import '../routes.dart';
import '../services/network_status_service.dart'; import '../services/network_status_service.dart';
import '../services/timeline_manager.dart'; import '../services/timeline_manager.dart';
@ -24,38 +24,11 @@ class UserPostsScreen extends StatelessWidget {
context, context,
'User Posts', 'User Posts',
actions: [ actions: [
ValueListenableBuilder( StatusAndRefreshButton(
valueListenable: nss.timelineLoadingStatus, valueListenable: nss.timelineLoadingStatus,
builder: (context2, executing, _) { refreshFunction: () async => await manager.updateTimeline(
if (executing) { timeline, TimelineRefreshType.refresh),
final theme = Theme.of(context); busyColor: Theme.of(context).colorScheme.background,
final size = theme.appBarTheme.actionsIconTheme?.size ??
theme.iconTheme.size ??
24;
return Center(
child: SizedBox(
width: size,
height: size,
child: CircularProgressIndicator(
color: Theme.of(context).canvasColor,
),
),
);
}
return IconButton(
onPressed: () async => await manager.updateTimeline(
timeline, TimelineRefreshType.refresh),
icon: Icon(
Icons.refresh,
));
}),
IconButton(
onPressed: () {
Navigator.of(context).popUntil((route) {
return route.settings.name == ScreenPaths.timelines;
});
},
icon: const Icon(Icons.home),
), ),
], ],
), ),