Skip to content

Commit

Permalink
Added country mapping for social link.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Mar 22, 2024
1 parent 2498af8 commit 8374a9d
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 22 deletions.
3 changes: 3 additions & 0 deletions assets/images/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/images/instagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/instagram_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/telegram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 111 additions & 21 deletions lib/account/follow_us.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import 'package:url_launcher/url_launcher.dart';

import '../common/common.dart';

enum _social {
enum _Social {
facebook,
x,
instagram,
telegram,
}

class FollowUs extends StatelessWidget {
const FollowUs({super.key});
class FollowUs extends StatefulWidget {
FollowUs({super.key});

@override
State<FollowUs> createState() => _FollowUsState();
}

class _FollowUsState extends State<FollowUs> {
@override
Widget build(BuildContext context) {
return Padding(
Expand All @@ -22,45 +29,128 @@ class FollowUs extends StatelessWidget {
const SizedBox(height: 5),
const CDivider(),
ListItemFactory.settingsItem(
icon: ImagePaths.thumbUp,
icon: ImagePaths.telegram,
content: 'follow_us_telegram'.i18n,
height: 60,
onTap: () => onSocialTap(_social.telegram),
onTap: () => onSocialTap(_Social.telegram),
),
ListItemFactory.settingsItem(
icon: ImagePaths.thumbUp,
icon: ImagePaths.x,
content: 'follow_us_x'.i18n,
height: 60,
onTap: () => onSocialTap(_social.x),
onTap: () => onSocialTap(_Social.x),
),
ListItemFactory.settingsItem(
icon: ImagePaths.thumbUp,
icon: ImagePaths.instagram,
content: 'follow_us_instagram'.i18n,
height: 60,
onTap: () => onSocialTap(_social.instagram),
onTap: () => onSocialTap(_Social.instagram),
),
ListItemFactory.settingsItem(
icon: ImagePaths.thumbUp,
icon: ImagePaths.facebook,
content: 'follow_us_facebook'.i18n,
height: 60,
onTap: () => onSocialTap(_social.facebook),
onTap: () => onSocialTap(_Social.facebook),
),
const SizedBox(height: 20),
],
),
);
}

void onSocialTap(_social social) {
switch (social) {
case _social.facebook:
// TODO: Handle this case.
case _social.x:
// TODO: Handle this case.
case _social.instagram:
// TODO: Handle this case.
case _social.telegram:
// TODO: Handle this case.
final countryMap = {
//Russia
'ru': {
_Social.facebook:
'https://www.facebook.com/profile.php?id=61555417626781',
_Social.x: 'https://twitter.com/Lantern_Russia',
_Social.instagram: 'https://www.instagram.com/lantern.io_ru',
_Social.telegram: 'https://t.me/lantern_russia',
},
//iran
'ir': {
_Social.facebook: 'https://www.facebook.com/getlanternpersian',
_Social.x: 'https://twitter.com/getlantern_fa',
_Social.instagram: 'https://www.instagram.com/getlantern_fa/',
_Social.telegram: 'https://t.me/LanternFarsi',
},
//Ukraine
'ua': {
_Social.facebook:
'https://www.facebook.com/profile.php?id=61554740875416',
_Social.x: ' https://twitter.com/LanternUA',
_Social.instagram: 'https://www.instagram.com/getlantern_ua/',
_Social.telegram: ' https://t.me/lanternukraine',
},
//Belarus
'by': {
_Social.facebook:
'https://www.facebook.com/profile.php?id=61554406268221',
_Social.x: 'https://twitter.com/LanternBelarus',
_Social.instagram: 'https://www.instagram.com/getlantern_belarus/',
_Social.telegram: 'https://t.me/lantern_belarus',
},
//United Arab Emirates
'uae': {
_Social.facebook:
'https://www.facebook.com/profile.php?id=61554655199439',
_Social.x: ' https://twitter.com/getlantern_UAE',
_Social.instagram: 'https://www.instagram.com/lanternio_uae/',
_Social.telegram: 'https://t.me/lantern_uae',
},
//Guinea
'gn': {
_Social.facebook:
'https://www.facebook.com/profile.php?id=61554620251833',
_Social.x: 'https://twitter.com/getlantern_gu',
_Social.instagram: 'https://www.instagram.com/lanternio_guinea/',
_Social.telegram: ': https://t.me/LanternGuinea',
},
'all': {
_Social.facebook: ' https://www.facebook.com/getlantern',
_Social.x: 'https://twitter.com/getlantern',
_Social.instagram: 'https://www.instagram.com/getlantern/',
_Social.telegram: '',
},
};

void onSocialTap(_Social social) {
//find the country of user
final countryCode = sessionModel.country.value ?? '';
if (countryCode != '') {
final currentSocialMap = countryMap[countryCode];
if (currentSocialMap != null) {
// we have fine country in our list
final url = currentSocialMap[social]!;
shareTap(
Uri.parse(url),
);
} else {
// we don't have country in our list
// use all country
final currentSocialMap = countryMap['all']!;
final url = currentSocialMap[social]!;
shareTap(Uri.parse(url));
}
} else {
// we don't have country in our list
// use all country
final currentSocialMap = countryMap['all']!;
final url = currentSocialMap[social]!;
shareTap(Uri.parse(url));
}
}

Future<void> shareTap(Uri url) async {
context.maybePop();
if (url.hasEmptyPath) {
showSnackbar(
context: context,
content:
'We are currently experiencing technical difficulties with retrieving the link. Please try again later.',
duration: const Duration(seconds: 2));
return;
}
await launchUrl(url, mode: LaunchMode.externalApplication);
}
}
5 changes: 5 additions & 0 deletions lib/common/ui/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ImagePaths {
static const webMoney = 'assets/images/webmoney.svg';
static const bitcoin = 'assets/images/bitcoin.svg';
static const thumbUp = 'assets/images/thumb_up.svg';
static const facebook = 'assets/images/facebook.svg';
static const instagram = 'assets/images/instagram.svg';
static const x = 'assets/images/x.svg';
static const telegram = 'assets/images/telegram.svg';
static const instagramPng = 'assets/images/instagram_png.png';

// Messaging
static const more_vert = 'assets/images/more_vert.svg';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dependencies:
hexcolor: ^3.0.1

# URL & Sharing utilities
url_launcher: ^6.1.12
url_launcher: ^6.2.5
share_plus: ^7.1.0
flutter_inappwebview: ^6.0.0
flutter_windows_webview:
Expand Down

0 comments on commit 8374a9d

Please sign in to comment.