| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/standard_list.dart'; |
| 3 | import 'package:url_launcher/url_launcher.dart'; |
| 4 | |
| 5 | class SettingsLinkProviderCell extends StandardListRow { |
| 6 | SettingsLinkProviderCell( |
| 7 | {required String title, |
| 8 | required this.link, |
| 9 | required this.linkTitle, |
| 10 | this.icon, |
| 11 | this.iconColor}) |
| 12 | : super(title: title, isSelected: false, onTap: (BuildContext context) => _launchUrl(link)); |
| 13 | |
| 14 | final String link; |
| 15 | final String linkTitle; |
| 16 | final String? icon; |
| 17 | final Color? iconColor; |
| 18 | |
| 19 | @override |
| 20 | Widget? buildLeading(BuildContext context) => |
| 21 | icon != null ? Image.asset(icon!, color: iconColor, height: 24, width: 24) : null; |
| 22 | |
| 23 | @override |
| 24 | Widget buildTrailing(BuildContext context) => Text( |
| 25 | linkTitle, |
| 26 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 27 | fontWeight: FontWeight.w500, |
| 28 | color: Theme.of(context).colorScheme.primary, |
| 29 | ), |
| 30 | ); |
| 31 | |
| 32 | static void _launchUrl(String url) async { |
| 33 | try { |
| 34 | final uri = Uri.parse(url); |
| 35 | if (await canLaunchUrl(uri)) await launchUrl(uri, mode: LaunchMode.externalApplication); |
| 36 | } catch (e) {} |
| 37 | } |
| 38 | } |