Skip to content

Commit e9d6696

Browse files
committed
feat: ✨ Add web compatibility
1 parent 3f8b2a5 commit e9d6696

7 files changed

Lines changed: 96 additions & 61 deletions

File tree

example/pubspec.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,26 @@ packages:
532532
dependency: transitive
533533
description:
534534
name: leak_tracker
535-
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
535+
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
536536
url: "https://pub.dev"
537537
source: hosted
538-
version: "10.0.0"
538+
version: "10.0.4"
539539
leak_tracker_flutter_testing:
540540
dependency: transitive
541541
description:
542542
name: leak_tracker_flutter_testing
543-
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
543+
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
544544
url: "https://pub.dev"
545545
source: hosted
546-
version: "2.0.1"
546+
version: "3.0.3"
547547
leak_tracker_testing:
548548
dependency: transitive
549549
description:
550550
name: leak_tracker_testing
551-
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
551+
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
552552
url: "https://pub.dev"
553553
source: hosted
554-
version: "2.0.1"
554+
version: "3.0.1"
555555
lints:
556556
dependency: transitive
557557
description:
@@ -596,10 +596,10 @@ packages:
596596
dependency: transitive
597597
description:
598598
name: meta
599-
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
599+
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
600600
url: "https://pub.dev"
601601
source: hosted
602-
version: "1.11.0"
602+
version: "1.12.0"
603603
mime:
604604
dependency: transitive
605605
description:
@@ -985,10 +985,10 @@ packages:
985985
dependency: transitive
986986
description:
987987
name: test_api
988-
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
988+
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
989989
url: "https://pub.dev"
990990
source: hosted
991-
version: "0.6.1"
991+
version: "0.7.0"
992992
timing:
993993
dependency: transitive
994994
description:
@@ -1113,10 +1113,10 @@ packages:
11131113
dependency: transitive
11141114
description:
11151115
name: vm_service
1116-
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
1116+
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
11171117
url: "https://pub.dev"
11181118
source: hosted
1119-
version: "13.0.0"
1119+
version: "14.2.1"
11201120
wallet:
11211121
dependency: transitive
11221122
description:

lib/pages/get_wallet_page.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22
import 'dart:math';
33

4+
import 'package:flutter/foundation.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter_svg/flutter_svg.dart';
67
import 'package:url_launcher/url_launcher.dart';
@@ -49,9 +50,11 @@ class GetWalletPage extends StatelessWidget {
4950
return WalletsList(
5051
itemList: itemsToShow,
5152
onTapWallet: (data) {
52-
final url = Platform.isIOS
53-
? data.listing.appStore
54-
: data.listing.playStore;
53+
final url = kIsWeb
54+
? data.listing.webappLink
55+
: Platform.isIOS
56+
? data.listing.appStore
57+
: data.listing.playStore;
5558
if ((url ?? '').isNotEmpty) {
5659
urlUtils.instance.launchUrl(
5760
Uri.parse(url!),

lib/services/explorer_service/explorer_service.dart

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22
import 'dart:convert';
3-
import 'dart:io';
43

54
import 'package:collection/collection.dart';
65
import 'package:flutter/foundation.dart';
@@ -201,7 +200,7 @@ class ExplorerService implements IExplorerService {
201200
_core.projectId,
202201
_referer,
203202
);
204-
final uri = Platform.isIOS
203+
final uri = platformUtils.instance.getPlatformExact() == PlatformExact.iOS
205204
? Uri.parse('${UrlConstants.apiService}/getIosData')
206205
: Uri.parse('${UrlConstants.apiService}/getAndroidData');
207206
try {
@@ -211,7 +210,12 @@ class ExplorerService implements IExplorerService {
211210
jsonDecode(response.body),
212211
(json) => NativeAppData.fromJson(json),
213212
);
214-
return apiResponse.data.toList();
213+
final result = apiResponse.data.toList();
214+
loggerService.instance.d(
215+
'[$runtimeType] fetched native data : ${result.map((appData) => jsonEncode(appData.toJson()))}',
216+
error: response.statusCode,
217+
);
218+
return result;
215219
} else {
216220
loggerService.instance.d(
217221
'⛔ [$runtimeType] error fetching native data $uri',
@@ -423,6 +427,9 @@ class ExplorerService implements IExplorerService {
423427

424428
@override
425429
Future<W3MWalletInfo?> getCoinbaseWalletObject() async {
430+
if (platformUtils.instance.getPlatformType() == PlatformType.web) {
431+
return null;
432+
}
426433
final results = await _fetchListings(
427434
params: RequestParams(
428435
page: 1,
@@ -486,15 +493,17 @@ class ExplorerService implements IExplorerService {
486493

487494
String _getPlatformType() {
488495
final type = platformUtils.instance.getPlatformType();
496+
final exactPlatform = platformUtils.instance.getPlatformExact();
489497
final platform = type.toString().toLowerCase();
490498
switch (type) {
491499
case PlatformType.mobile:
492-
if (Platform.isIOS) {
493-
return 'ios';
494-
} else if (Platform.isAndroid) {
495-
return 'android';
496-
} else {
497-
return 'mobile';
500+
switch (exactPlatform) {
501+
case PlatformExact.iOS:
502+
return 'ios';
503+
case PlatformExact.android:
504+
return 'android';
505+
default:
506+
return 'mobile';
498507
}
499508
default:
500509
return platform;

lib/utils/platform/platform_utils.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4-
import 'package:flutter/foundation.dart' show kIsWeb;
4+
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb;
55
import 'package:web3modal_flutter/utils/platform/i_platform_utils.dart';
66

77
class PlatformUtils extends IPlatformUtils {
8+
bool get _runsOnIos =>
9+
(kIsWeb && defaultTargetPlatform == TargetPlatform.iOS) ||
10+
(!kIsWeb && Platform.isIOS);
11+
bool get _runsOnAndroid =>
12+
(kIsWeb && defaultTargetPlatform == TargetPlatform.android) ||
13+
(!kIsWeb && Platform.isAndroid);
14+
815
@override
916
PlatformExact getPlatformExact() {
10-
if (Platform.isAndroid) {
17+
if (_runsOnAndroid) {
1118
return PlatformExact.android;
12-
} else if (Platform.isIOS) {
19+
} else if (_runsOnIos) {
1320
return PlatformExact.iOS;
21+
} else if (kIsWeb) {
22+
return PlatformExact.web;
1423
} else if (Platform.isLinux) {
1524
return PlatformExact.linux;
1625
} else if (Platform.isMacOS) {
1726
return PlatformExact.macOS;
1827
} else if (Platform.isWindows) {
1928
return PlatformExact.windows;
20-
} else if (kIsWeb) {
21-
return PlatformExact.web;
2229
}
2330
return PlatformExact.web;
2431
}
2532

2633
@override
2734
PlatformType getPlatformType() {
28-
if (Platform.isAndroid || Platform.isIOS) {
35+
if (_runsOnAndroid || _runsOnIos) {
2936
return PlatformType.mobile;
30-
} else if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
37+
} else if (!kIsWeb &&
38+
(Platform.isLinux || Platform.isMacOS || Platform.isWindows)) {
3139
return PlatformType.desktop;
3240
} else if (kIsWeb) {
3341
return PlatformType.web;

lib/utils/url/url_utils.dart

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class UrlUtils extends IUrlUtils {
4545

4646
@override
4747
Future<bool> isInstalled(String? uri, {String? id}) async {
48+
loggerService.instance.d(
49+
'[$runtimeType] $uri ($id): checking is app installed',
50+
);
51+
4852
if (uri == null || uri.isEmpty) {
4953
return false;
5054
}
@@ -54,23 +58,33 @@ class UrlUtils extends IUrlUtils {
5458
return false;
5559
}
5660

57-
if (platformUtils.instance.canDetectInstalledApps()) {
58-
final p = platformUtils.instance.getPlatformExact();
59-
try {
60-
if (p == PlatformExact.android) {
61-
return await androidAppCheck(uri);
62-
} else if (p == PlatformExact.iOS) {
63-
return await canLaunchUrlFunc(Uri.parse(uri));
64-
}
65-
} on FormatException catch (e) {
66-
if (id != null) {
67-
loggerService.instance.d('[$runtimeType] $uri ($id): ${e.message}');
68-
} else {
69-
loggerService.instance.d('[$runtimeType] $uri: ${e.message}');
70-
}
71-
} catch (e) {
72-
rethrow;
61+
final p = platformUtils.instance.getPlatformExact();
62+
if (!platformUtils.instance.canDetectInstalledApps()) {
63+
loggerService.instance.d(
64+
'[$runtimeType] $uri ($id): check abort - platform $p cannot detect installed apps',
65+
);
66+
return false;
67+
}
68+
try {
69+
if (p == PlatformExact.android) {
70+
loggerService.instance.d(
71+
'[$runtimeType] $uri ($id): checking the Android way',
72+
);
73+
return await androidAppCheck(uri);
74+
} else if (p == PlatformExact.iOS) {
75+
loggerService.instance.d(
76+
'[$runtimeType] $uri ($id): checking the iOS way',
77+
);
78+
return await canLaunchUrlFunc(Uri.parse(uri));
79+
}
80+
} on FormatException catch (e) {
81+
if (id != null) {
82+
loggerService.instance.d('[$runtimeType] $uri ($id): ${e.message}');
83+
} else {
84+
loggerService.instance.d('[$runtimeType] $uri: ${e.message}');
7385
}
86+
} catch (e) {
87+
rethrow;
7488
}
7589

7690
return false;

lib/widgets/lists/list_items/download_wallet_item.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io';
22

3+
import 'package:flutter/foundation.dart';
34
import 'package:flutter/material.dart';
45
import 'package:url_launcher/url_launcher_string.dart';
56

@@ -21,10 +22,10 @@ class DownloadWalletItem extends StatelessWidget {
2122
if (webOnly) {
2223
return walletInfo.listing.homepage;
2324
}
24-
if (Platform.isIOS) {
25+
if (kIsWeb == false && Platform.isIOS) {
2526
return walletInfo.listing.appStore ?? '';
2627
}
27-
if (Platform.isAndroid) {
28+
if (kIsWeb == false && Platform.isAndroid) {
2829
return walletInfo.listing.playStore ?? '';
2930
}
3031
return '';

pubspec.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,26 +492,26 @@ packages:
492492
dependency: transitive
493493
description:
494494
name: leak_tracker
495-
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
495+
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
496496
url: "https://pub.dev"
497497
source: hosted
498-
version: "10.0.0"
498+
version: "10.0.4"
499499
leak_tracker_flutter_testing:
500500
dependency: transitive
501501
description:
502502
name: leak_tracker_flutter_testing
503-
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
503+
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
504504
url: "https://pub.dev"
505505
source: hosted
506-
version: "2.0.1"
506+
version: "3.0.3"
507507
leak_tracker_testing:
508508
dependency: transitive
509509
description:
510510
name: leak_tracker_testing
511-
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
511+
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
512512
url: "https://pub.dev"
513513
source: hosted
514-
version: "2.0.1"
514+
version: "3.0.1"
515515
lints:
516516
dependency: "direct dev"
517517
description:
@@ -556,10 +556,10 @@ packages:
556556
dependency: transitive
557557
description:
558558
name: meta
559-
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
559+
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
560560
url: "https://pub.dev"
561561
source: hosted
562-
version: "1.11.0"
562+
version: "1.12.0"
563563
mime:
564564
dependency: transitive
565565
description:
@@ -961,10 +961,10 @@ packages:
961961
dependency: transitive
962962
description:
963963
name: test_api
964-
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
964+
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
965965
url: "https://pub.dev"
966966
source: hosted
967-
version: "0.6.1"
967+
version: "0.7.0"
968968
timing:
969969
dependency: transitive
970970
description:
@@ -1089,10 +1089,10 @@ packages:
10891089
dependency: transitive
10901090
description:
10911091
name: vm_service
1092-
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
1092+
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
10931093
url: "https://pub.dev"
10941094
source: hosted
1095-
version: "13.0.0"
1095+
version: "14.2.1"
10961096
wallet:
10971097
dependency: transitive
10981098
description:

0 commit comments

Comments
 (0)