dev
dart 158 lines 6.45 KB
Raw
1 import 'package:cake_wallet/di.dart';
2 import 'package:cake_wallet/entities/preferences_key.dart';
3 import 'package:cake_wallet/entities/service_status.dart';
4 import 'package:cake_wallet/generated/i18n.dart';
5 import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
6 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
7 import 'package:cake_wallet/src/widgets/primary_button.dart';
8 import 'package:cake_wallet/src/widgets/service_status_tile.dart';
9 import 'package:cake_wallet/utils/device_info.dart';
10 import 'package:cake_wallet/utils/show_pop_up.dart';
11 import 'package:flutter/material.dart';
12 import 'package:shared_preferences/shared_preferences.dart';
13 import 'package:url_launcher/url_launcher.dart';
14
15 class ServicesUpdatesWidget extends StatefulWidget {
16 final Future<ServicesResponse> servicesResponse;
17 final bool enabled;
18
19 const ServicesUpdatesWidget(this.servicesResponse, {super.key, required this.enabled});
20
21 @override
22 State<ServicesUpdatesWidget> createState() => _ServicesUpdatesWidgetState();
23 }
24
25 class _ServicesUpdatesWidgetState extends State<ServicesUpdatesWidget> {
26 bool wasOpened = false;
27
28 @override
29 Widget build(BuildContext context) {
30 if (!widget.enabled) {
31 return InkWell(
32 onTap: () async {
33 await showPopUp<void>(
34 context: context,
35 builder: (BuildContext context) {
36 return AlertWithOneAction(
37 alertTitle: S.current.service_health_disabled,
38 alertContent: S.current.service_health_disabled_message,
39 buttonText: S.current.ok,
40 buttonAction: () => Navigator.of(context).pop(),
41 );
42 });
43 },
44 child: CakeImageWidget(
45 imageUrl: "assets/images/notif.svg",
46 color: Theme.of(context).colorScheme.primary,
47 width: DeviceInfo.instance.isDesktop ? 30 : 20,
48 ),
49 );
50 }
51 return Padding(
52 padding: DeviceInfo.instance.isDesktop
53 ? EdgeInsets.zero
54 : EdgeInsets.only(left: 16, top: 12, right: 8, bottom: 8),
55 child: FutureBuilder<ServicesResponse>(
56 future: widget.servicesResponse,
57 builder: (context, state) {
58 return InkWell(
59 onTap: state.hasData
60 ? () {
61 // save currentSha when the user see the status
62 getIt
63 .get<SharedPreferences>()
64 .setString(PreferencesKey.serviceStatusShaKey, state.data!.currentSha);
65
66 setState(() => wasOpened = true);
67
68 showModalBottomSheet(
69 backgroundColor: Theme.of(context).colorScheme.surface,
70 context: context,
71 shape: RoundedRectangleBorder(
72 borderRadius: BorderRadius.only(
73 topLeft: Radius.circular(50),
74 topRight: Radius.circular(50),
75 ),
76 ),
77 constraints: BoxConstraints(
78 maxHeight: MediaQuery.of(context).size.height / 2,
79 minHeight: MediaQuery.of(context).size.height / 4,
80 ),
81 builder: (context) {
82 Widget body;
83 if (state.data!.servicesStatus.isEmpty) {
84 body = Center(
85 child: Text(
86 "Everything is up and running as expected",
87 style: Theme.of(context).textTheme.bodyMedium,
88 ),
89 );
90 } else {
91 body = SingleChildScrollView(
92 child: Column(
93 children: state.data!.servicesStatus
94 .map((status) => ServiceStatusTile(status))
95 .toList(),
96 ),
97 );
98 }
99 return Padding(
100 padding: const EdgeInsets.symmetric(horizontal: 12),
101 child: Column(
102 children: [
103 Expanded(child: body),
104 Align(
105 alignment: Alignment.bottomCenter,
106 child: Padding(
107 padding: EdgeInsets.symmetric(
108 horizontal: 24,
109 vertical: 20,
110 ),
111 child: PrimaryButton(
112 onPressed: () {
113 try {
114 launchUrl(
115 Uri.parse(
116 "https://status.cakewallet.com/",
117 ),
118 mode: LaunchMode.externalApplication);
119 } catch (_) {}
120 },
121 text: "Status Website",
122 color: Theme.of(context).colorScheme.primary,
123 textColor: Theme.of(context).colorScheme.onPrimary,
124 ),
125 ),
126 )
127 ],
128 ),
129 );
130 },
131 );
132 }
133 : null,
134 child: Stack(
135 children: [
136 CakeImageWidget(
137 imageUrl: "assets/images/notif.svg",
138 color: Theme.of(context).colorScheme.primary,
139 width: DeviceInfo.instance.isDesktop ? 30 : 20,
140 ),
141 if (state.hasData && state.data!.hasUpdates && !wasOpened)
142 Container(
143 height: 7,
144 width: 7,
145 margin: EdgeInsetsDirectional.only(start: 15),
146 decoration: BoxDecoration(
147 color: Theme.of(context).colorScheme.errorContainer,
148 shape: BoxShape.circle,
149 ),
150 ),
151 ],
152 ),
153 );
154 },
155 ),
156 );
157 }
158 }