2023-08-17 12:28:31 -03:00
|
|
|
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
|
2020-07-21 20:22:41 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2020-07-23 15:20:52 +03:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
2021-12-24 14:37:24 +02:00
|
|
|
import 'package:cake_wallet/core/sync_status_title.dart';
|
2020-07-21 20:22:41 +03:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2021-12-24 14:37:24 +02:00
|
|
|
import 'package:cw_core/sync_status.dart';
|
2022-02-21 16:30:48 +02:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
class SyncIndicator extends StatelessWidget {
|
2024-09-22 03:46:51 +01:00
|
|
|
SyncIndicator({
|
|
|
|
required this.dashboardViewModel,
|
|
|
|
required this.onTap,
|
|
|
|
super.key,
|
|
|
|
});
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
final DashboardViewModel dashboardViewModel;
|
2022-03-08 13:11:55 +02:00
|
|
|
final Function() onTap;
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Observer(
|
|
|
|
builder: (_) {
|
2020-08-19 20:57:06 +03:00
|
|
|
final syncIndicatorWidth = 237.0;
|
2020-07-21 20:22:41 +03:00
|
|
|
final status = dashboardViewModel.status;
|
2025-03-21 04:18:47 +02:00
|
|
|
final statusText = syncStatusTitle(status);
|
|
|
|
final progress = status.progress();
|
2020-07-21 20:22:41 +03:00
|
|
|
final indicatorOffset = progress * syncIndicatorWidth;
|
2020-08-19 20:57:06 +03:00
|
|
|
final indicatorWidth = progress < 1
|
|
|
|
? indicatorOffset > 0 ? indicatorOffset : 0.0
|
|
|
|
: syncIndicatorWidth;
|
2022-02-21 16:30:48 +02:00
|
|
|
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
return ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(15)),
|
2022-03-08 13:11:55 +02:00
|
|
|
child: GestureDetector(
|
|
|
|
onTap: onTap,
|
2020-07-21 20:22:41 +03:00
|
|
|
child: Container(
|
|
|
|
height: 30,
|
|
|
|
width: syncIndicatorWidth,
|
2023-08-17 12:28:31 -03:00
|
|
|
color: Theme.of(context).extension<SyncIndicatorTheme>()!.notSyncedBackgroundColor,
|
2020-07-21 20:22:41 +03:00
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
progress <= 1
|
|
|
|
? Positioned(
|
2020-08-19 20:57:06 +03:00
|
|
|
left: 0,
|
2020-07-21 20:22:41 +03:00
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
child: Container(
|
|
|
|
width: indicatorWidth,
|
|
|
|
height: 30,
|
2023-08-17 12:28:31 -03:00
|
|
|
color: Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor,
|
2020-07-21 20:22:41 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
: Offstage(),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
right: 24
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2022-02-21 16:30:48 +02:00
|
|
|
SyncIndicatorIcon(isSynced:status is SyncedSyncStatus),
|
2020-07-21 20:22:41 +03:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 6),
|
|
|
|
child: Text(
|
|
|
|
statusText,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
2020-07-22 13:04:11 +03:00
|
|
|
fontWeight: FontWeight.w500,
|
2023-08-17 12:28:31 -03:00
|
|
|
color: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor
|
2020-07-21 20:22:41 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-03-08 13:11:55 +02:00
|
|
|
));
|
2020-07-21 20:22:41 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|