Files
meshcore-open/lib/widgets/sync_progress_overlay.dart
T
celsoazevedoandClaude Opus 5.5 5b74383d10 Settings actions: messages and radio progress
Every action ends with a short message: Sync Time ("Time sent to the
radio"), Refresh Contacts, Reboot and Delete All Paths. While Refresh
Contacts or Reboot wait for the radio, the row shows a spinner
(MeshNavTile busy) and the app bar the shared progress bar. Delete All
Paths now says it clears the app's path history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 06:35:12 +00:00

91 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
/// The thin progress bar at the top of a screen or list: 4px, in the theme's
/// progress colour and track. Fills when [value] is known, moves when it is
/// null. While inactive it keeps its height, so the content doesn't jump.
class MeshProgressBar extends StatelessWidget {
static const double height = 4;
final bool active;
final double? value;
const MeshProgressBar({super.key, this.active = true, this.value});
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
child: active
? LinearProgressIndicator(value: value, minHeight: height)
: null,
);
}
}
/// [MeshProgressBar] as an app bar's `bottom`, for a screen's own task.
class MeshProgressAppBarBottom extends StatelessWidget
implements PreferredSizeWidget {
final bool active;
final double? value;
const MeshProgressAppBarBottom({super.key, this.active = true, this.value});
@override
Size get preferredSize => const Size.fromHeight(MeshProgressBar.height);
@override
Widget build(BuildContext context) =>
MeshProgressBar(active: active, value: value);
}
/// [MeshProgressBar] as an app bar's `bottom` for the app-wide syncs:
/// contacts, channels and queued messages, one at a time.
class SyncProgressAppBarBottom extends StatelessWidget
implements PreferredSizeWidget {
/// Also shows the bar, moving, while the screen waits for the radio and no
/// sync is running.
final bool busy;
const SyncProgressAppBarBottom({super.key, this.busy = false});
@override
Size get preferredSize => const Size.fromHeight(MeshProgressBar.height);
@override
Widget build(BuildContext context) {
return Consumer<MeshCoreConnector>(
builder: (context, connector, _) {
final state =
_SyncProgressState.fromConnector(connector) ??
(busy && connector.isConnected
? const _SyncProgressState(value: null)
: null);
return MeshProgressBar(active: state != null, value: state?.value);
},
);
}
}
class _SyncProgressState {
/// Null while the progress is unknown.
final double? value;
const _SyncProgressState({required this.value});
static _SyncProgressState? fromConnector(MeshCoreConnector connector) {
if (connector.isLoadingContacts) {
return _SyncProgressState(value: connector.contactSyncProgress);
}
if (connector.isSyncingChannels) {
return _SyncProgressState(value: connector.channelSyncProgress / 100);
}
if (connector.isShowingQueuedMessageSyncProgress) {
return const _SyncProgressState(value: null);
}
return null;
}
}