dev
dart 87 lines 3.28 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
3 import 'package:cake_wallet/core/sync_status_title.dart';
4 import 'package:flutter_mobx/flutter_mobx.dart';
5 import 'package:cw_core/sync_status.dart';
6 import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
7
8 class SyncIndicator extends StatelessWidget {
9 SyncIndicator({
10 required this.dashboardViewModel,
11 required this.onTap,
12 super.key,
13 });
14
15 final DashboardViewModel dashboardViewModel;
16 final Function() onTap;
17
18 @override
19 Widget build(BuildContext context) {
20 return Observer(builder: (_) {
21 final syncIndicatorWidth = 237.0;
22 final status = dashboardViewModel.status;
23 final statusText =
24 syncStatusTitle(status, dashboardViewModel.settingsStore.syncStatusDisplayMode);
25 final progress = status.progress();
26 final indicatorOffset = progress * syncIndicatorWidth;
27 final indicatorWidth = progress < 1
28 ? indicatorOffset > 0
29 ? indicatorOffset
30 : 0.0
31 : syncIndicatorWidth;
32
33 return ClipRRect(
34 borderRadius: BorderRadius.all(Radius.circular(15)),
35 child: GestureDetector(
36 onTap: onTap,
37 onLongPress: dashboardViewModel.toggleSwitchStatusDisplayMode,
38 child: Container(
39 height: 30,
40 width: syncIndicatorWidth,
41 color: Theme.of(context).colorScheme.surfaceContainerLow,
42 child: Stack(
43 alignment: Alignment.center,
44 children: <Widget>[
45 progress <= 1
46 ? Positioned(
47 left: 0,
48 top: 0,
49 bottom: 0,
50 child: Container(
51 width: indicatorWidth,
52 height: 30,
53 color: Theme.of(context).colorScheme.surfaceContainer,
54 ))
55 : Offstage(),
56 Padding(
57 padding: EdgeInsets.only(left: 24, right: 24),
58 child: Row(
59 mainAxisSize: MainAxisSize.max,
60 mainAxisAlignment: MainAxisAlignment.center,
61 crossAxisAlignment: CrossAxisAlignment.center,
62 children: <Widget>[
63 SyncIndicatorIcon(
64 isSynced: status is SyncedSyncStatus,
65 showTorIcon: dashboardViewModel.builtinTor,
66 size: dashboardViewModel.builtinTor ? 16 : 6,
67 ),
68 Padding(
69 padding: EdgeInsets.only(left: 6),
70 child: Text(
71 statusText,
72 style: Theme.of(context).textTheme.bodySmall?.copyWith(
73 fontWeight: FontWeight.w500,
74 color: Theme.of(context).colorScheme.onSurface,
75 ),
76 ),
77 )
78 ],
79 ),
80 )
81 ],
82 ),
83 ),
84 ));
85 });
86 }
87 }