1
- import 'dart:io' ;
2
-
3
1
import 'package:flutter/material.dart' ;
4
2
import 'package:flutter/services.dart' ;
5
3
import 'package:provider/provider.dart' ;
@@ -11,7 +9,6 @@ import 'package:rcp/screens/main_screen/section_tittle_widget.dart';
11
9
import 'package:rcp/screens/main_screen/silver_appbar_widget.dart' ;
12
10
import 'package:rcp/screens/main_screen/single_cat_grid_widget.dart' ;
13
11
import 'package:url_launcher/url_launcher.dart' ;
14
- import 'package:url_launcher/url_launcher_string.dart' ;
15
12
16
13
import 'carusel_widget.dart' ;
17
14
import 'main_bottombar_screen.dart' ;
@@ -26,37 +23,10 @@ class MainScreen extends StatefulWidget {
26
23
class _MainScreenState extends State <MainScreen > {
27
24
final Uri _url = Uri .parse ('https://racingcustomparts.com/' );
28
25
29
- final instaLink = 'https://www.instagram.com/racingcustomparts/' ;
26
+ final instaLink = Uri .parse ('https://www.instagram.com/racingcustomparts/' );
27
+ final fbLink = Uri .parse ('https://www.facebook.com/RacingCustomParts/' );
30
28
late bool switchThemeMode;
31
29
32
- Future <void > _openFacebook () async {
33
- HapticFeedback .mediumImpact ();
34
-
35
- String fbProtocolUrl;
36
- if (Platform .isIOS) {
37
- fbProtocolUrl = 'fb://profile/1422674971360874' ;
38
- } else {
39
- fbProtocolUrl = 'fb://page/1422674971360874' ;
40
- }
41
-
42
- String fallbackUrl = 'https://www.facebook.com/RacingCustomParts' ;
43
-
44
- try {
45
- Uri fbBundleUri = Uri .parse (fbProtocolUrl);
46
- var canLaunchNatively = await canLaunchUrl (fbBundleUri);
47
-
48
- if (canLaunchNatively) {
49
- launchUrl (fbBundleUri);
50
- } else {
51
- await launchUrl (Uri .parse (fallbackUrl),
52
- mode: LaunchMode .externalApplication);
53
- }
54
- } catch (error) {
55
- Provider .of <SettingAppProvider >(context, listen: false )
56
- .showErrorDialog (error, context);
57
- }
58
- }
59
-
60
30
Future <void > _launchUrlToBroswer () async {
61
31
HapticFeedback .lightImpact ();
62
32
try {
@@ -69,19 +39,20 @@ class _MainScreenState extends State<MainScreen> {
69
39
}
70
40
}
71
41
72
- Future <void > _launchSocialMediaAppIfInstalled (
73
- {required String appLink, String ? alternative}) async {
74
- HapticFeedback .mediumImpact ();
42
+ Future <void > _launchSocialMediaAppIfInstalled ({
43
+ required Uri url,
44
+ }) async {
45
+ HapticFeedback .lightImpact ();
46
+
47
+ try {
48
+ bool launched = await launchUrl (url,
49
+ mode: LaunchMode .externalApplication); // Launch the app if installed!
75
50
76
- bool launched = await launchUrlString (
77
- appLink,
78
- mode: LaunchMode .externalApplication,
79
- );
80
- if (! launched) {
81
- await launchUrlString (
82
- alternative as String ); // Launch web view if app is not installed!
83
- } else {
84
- launchUrlString (appLink);
51
+ if (! launched) {
52
+ launchUrl (url); // Launch web view if app is not installed!
53
+ }
54
+ } catch (e) {
55
+ launchUrl (url); // Launch web view if app is not installed!
85
56
}
86
57
}
87
58
@@ -183,7 +154,7 @@ class _MainScreenState extends State<MainScreen> {
183
154
.withOpacity (0.4 ),
184
155
blendColorl: const Color .fromARGB (209 , 9 , 37 , 83 ),
185
156
callback: () {
186
- _openFacebook ( );
157
+ _launchSocialMediaAppIfInstalled (url : fbLink );
187
158
},
188
159
imageSrc: 'assets/images/tsunami.jpeg' ,
189
160
icon: Icons .facebook,
@@ -194,8 +165,7 @@ class _MainScreenState extends State<MainScreen> {
194
165
.withOpacity (0.4 ),
195
166
blendColorl: const Color .fromARGB (190 , 73 , 6 , 62 ),
196
167
callback: () {
197
- _launchSocialMediaAppIfInstalled (
198
- appLink: instaLink);
168
+ _launchSocialMediaAppIfInstalled (url: instaLink);
199
169
},
200
170
imageSrc: 'assets/images/drag.jpeg' ,
201
171
icon: Icons .photo_camera,
0 commit comments