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

Wyświetl plik

@ -4,6 +4,7 @@ import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../globals.dart';
import '../serializers/friendica/image_entry_friendica_extensions.dart';
import '../services/gallery_service.dart';
@ -29,33 +30,15 @@ class GalleryScreen extends StatelessWidget {
);
return Scaffold(
appBar: StandardAppBar.build(context, galleryName, actions: [
ValueListenableBuilder(
valueListenable: nss.imageGalleryLoadingStatus,
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: Theme.of(context).canvasColor),
),
);
}
return IconButton(
onPressed: () async => await service.updateGalleryImageList(
galleryName: galleryName,
withNextPage: false,
nextPageOnly: false,
),
icon: Icon(
Icons.refresh,
));
}),
StatusAndRefreshButton(
valueListenable: nss.imageGalleryLoadingStatus,
refreshFunction: () async => await service.updateGalleryImageList(
galleryName: galleryName,
withNextPage: false,
nextPageOnly: false,
),
busyColor: Theme.of(context).appBarTheme.foregroundColor,
),
]),
body: body,
);

Wyświetl plik

@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../controls/app_bottom_nav_bar.dart';
import '../controls/padding.dart';
import '../controls/status_and_refresh_button.dart';
import '../controls/timeline/timeline_panel.dart';
import '../globals.dart';
import '../models/TimelineIdentifiers.dart';
@ -81,30 +82,12 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
actions: [
ValueListenableBuilder(
valueListenable: nss.timelineLoadingStatus,
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: const CircularProgressIndicator(),
),
);
}
return IconButton(
onPressed: () async => await manager.updateTimeline(
currentTimeline, TimelineRefreshType.refresh),
icon: Icon(
Icons.refresh,
color: Theme.of(context).textTheme.bodyLarge?.color,
));
}),
StatusAndRefreshButton(
valueListenable: nss.timelineLoadingStatus,
refreshFunction: () async => await manager.updateTimeline(
currentTimeline, TimelineRefreshType.refresh),
buttonColor: Theme.of(context).textTheme.bodyLarge?.color,
),
IconButton(
onPressed: () {
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/notifications_control.dart';
import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../globals.dart';
import '../services/network_status_service.dart';
import '../services/notifications_manager.dart';
@ -53,28 +54,11 @@ class NotificationsScreen extends StatelessWidget {
context,
title,
actions: [
ValueListenableBuilder(
valueListenable: nss.notificationsUpdateStatus,
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: theme.canvasColor,
),
),
);
}
return IconButton(
onPressed: () async => await manager.updateNotifications(),
icon: const Icon(Icons.refresh));
}),
StatusAndRefreshButton(
valueListenable: nss.notificationsUpdateStatus,
refreshFunction: () async => manager.updateNotifications(),
busyColor: Theme.of(context).colorScheme.background,
),
IconButton(
onPressed: () async => _clearAllNotifications(context, manager),
icon: const Icon(Icons.cleaning_services),

Wyświetl plik

@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../controls/standard_appbar.dart';
import '../controls/status_and_refresh_button.dart';
import '../controls/timeline/timeline_panel.dart';
import '../globals.dart';
import '../models/TimelineIdentifiers.dart';
import '../routes.dart';
import '../services/network_status_service.dart';
import '../services/timeline_manager.dart';
@ -24,38 +24,11 @@ class UserPostsScreen extends StatelessWidget {
context,
'User Posts',
actions: [
ValueListenableBuilder(
valueListenable: nss.timelineLoadingStatus,
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: 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),
StatusAndRefreshButton(
valueListenable: nss.timelineLoadingStatus,
refreshFunction: () async => await manager.updateTimeline(
timeline, TimelineRefreshType.refresh),
busyColor: Theme.of(context).colorScheme.background,
),
],
),