Merge pull request #709 from celsoazevedo/progress-bars
Progress bars: one shared 4px top bar in the theme colour
This commit is contained in:
7 files changed
+112
-48
No files matched your search
@@ -8,6 +8,7 @@ import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import 'chat_day_separator.dart';
|
||||
import 'empty_state.dart';
|
||||
import 'sync_progress_overlay.dart';
|
||||
|
||||
/// Results list for "search in this chat". Loads the full history through
|
||||
/// [loadEntries] (once, cached) and re-filters on each debounced [query].
|
||||
@@ -86,10 +87,7 @@ class _ChatSearchResultsState extends State<ChatSearchResults> {
|
||||
final showEmpty = !_loading && _results.isEmpty;
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 3,
|
||||
child: _loading ? const LinearProgressIndicator() : null,
|
||||
),
|
||||
MeshProgressBar(active: _loading),
|
||||
if (!_loading && _results.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 6),
|
||||
|
||||
@@ -3,57 +3,79 @@ 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 {
|
||||
static const double height = 3;
|
||||
|
||||
const SyncProgressAppBarBottom({super.key});
|
||||
|
||||
@override
|
||||
Size get preferredSize => const Size.fromHeight(height);
|
||||
Size get preferredSize => const Size.fromHeight(MeshProgressBar.height);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final state = _SyncProgressState.fromConnector(connector);
|
||||
if (state == null) return const SizedBox(height: height);
|
||||
|
||||
return SizedBox(
|
||||
height: height,
|
||||
child: LinearProgressIndicator(
|
||||
value: state.value,
|
||||
minHeight: height,
|
||||
color: state.color,
|
||||
backgroundColor: state.color.withValues(alpha: 0.18),
|
||||
),
|
||||
);
|
||||
return MeshProgressBar(active: state != null, value: state?.value);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SyncProgressState {
|
||||
/// Null while the progress is unknown.
|
||||
final double? value;
|
||||
final Color color;
|
||||
|
||||
const _SyncProgressState({required this.value, required this.color});
|
||||
const _SyncProgressState({required this.value});
|
||||
|
||||
static _SyncProgressState? fromConnector(MeshCoreConnector connector) {
|
||||
if (connector.isLoadingContacts) {
|
||||
return _SyncProgressState(
|
||||
value: connector.contactSyncProgress,
|
||||
color: Colors.red,
|
||||
);
|
||||
return _SyncProgressState(value: connector.contactSyncProgress);
|
||||
}
|
||||
if (connector.isSyncingChannels) {
|
||||
return _SyncProgressState(
|
||||
value: connector.channelSyncProgress / 100,
|
||||
color: Colors.blue,
|
||||
);
|
||||
return _SyncProgressState(value: connector.channelSyncProgress / 100);
|
||||
}
|
||||
if (connector.isShowingQueuedMessageSyncProgress) {
|
||||
return const _SyncProgressState(value: null, color: Colors.green);
|
||||
return const _SyncProgressState(value: null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user