mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-10 07:50:28 -07:00
feature: Re-implemented syncing
This commit is contained in:
parent
c5c7f71b84
commit
86ff355e21
51 changed files with 3067 additions and 1147 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:iconsax_plus/iconsax_plus.dart';
|
||||
|
||||
|
|
@ -7,48 +8,44 @@ import 'package:fladder/models/item_base_model.dart';
|
|||
import 'package:fladder/models/syncing/sync_item.dart';
|
||||
import 'package:fladder/providers/sync/sync_provider_helpers.dart';
|
||||
|
||||
class SyncButton extends ConsumerStatefulWidget {
|
||||
class SyncButton extends ConsumerWidget {
|
||||
final ItemBaseModel item;
|
||||
final SyncedItem? syncedItem;
|
||||
final SyncedItem syncedItem;
|
||||
const SyncButton({required this.item, required this.syncedItem, super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() => _SyncButtonState();
|
||||
}
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final nested = ref.watch(syncedNestedChildrenProvider(syncedItem));
|
||||
return nested.when(
|
||||
loading: () => const SizedBox.shrink(),
|
||||
error: (err, stack) => const SizedBox.shrink(),
|
||||
data: (children) {
|
||||
final download = ref.watch(syncDownloadStatusProvider(syncedItem, children));
|
||||
final status = download?.status ?? TaskStatus.notFound;
|
||||
final progress = download?.progress ?? 0.0;
|
||||
|
||||
class _SyncButtonState extends ConsumerState<SyncButton> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final syncedItem = widget.syncedItem;
|
||||
final status = syncedItem != null ? ref.watch(syncStatusesProvider(syncedItem, null)).value : null;
|
||||
final progress = syncedItem != null ? ref.watch(syncDownloadStatusProvider(syncedItem, [])) : null;
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
syncedItem != null
|
||||
? status == SyncStatus.partially
|
||||
? (progress?.progress ?? 0) > 0
|
||||
? IconsaxPlusLinear.arrow_down
|
||||
: IconsaxPlusLinear.more_circle
|
||||
: IconsaxPlusLinear.tick_circle
|
||||
: IconsaxPlusLinear.arrow_down_2,
|
||||
color: status?.color,
|
||||
size: (progress?.progress ?? 0) > 0 ? 16 : null,
|
||||
),
|
||||
if ((progress?.progress ?? 0) > 0)
|
||||
IgnorePointer(
|
||||
child: SizedBox.fromSize(
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
status == TaskStatus.notFound
|
||||
? (progress > 0 ? IconsaxPlusLinear.arrow_down_1 : IconsaxPlusLinear.more_circle)
|
||||
: status.icon,
|
||||
color: status.color(context),
|
||||
size: status == TaskStatus.running && progress > 0 ? 16 : null,
|
||||
),
|
||||
SizedBox.fromSize(
|
||||
size: const Size.fromRadius(10),
|
||||
child: CircularProgressIndicator(
|
||||
strokeCap: StrokeCap.round,
|
||||
strokeWidth: 2,
|
||||
color: status?.color,
|
||||
value: progress?.progress,
|
||||
strokeWidth: 1.5,
|
||||
color: status.color(context),
|
||||
value: status == TaskStatus.running ? progress.clamp(0.0, 1.0) : 0,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue