Skip to content

Commit

Permalink
Open Urls in Company Detail Page . (#189)
Browse files Browse the repository at this point in the history
* Open Urls in Company Detail Page .

* Update lib/src/pages/company_details.dart

* Update lib/src/pages/company_details.dart

---------

Co-authored-by: Fred Falcon <7475382+fredfalcon@users.noreply.github.com>
  • Loading branch information
solo-daemon and fredfalcon committed Mar 2, 2023
1 parent 4a946c2 commit 93c5ff5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
47 changes: 44 additions & 3 deletions lib/src/pages/company_details.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../models/company_model.dart';
import 'package:url_launcher/url_launcher.dart';

/// Popup page for viewing company details when a company
/// is clicked on the Company Scoreboard page.
Expand All @@ -19,6 +19,43 @@ class CompanyDetailPage extends StatefulWidget {
class _CompanyDetailPageState extends State<CompanyDetailPage> {
late Color companyColor;

Future<void> redirectEmail(BuildContext context,Company company) async{
SnackBar emailSnack = SnackBar(
content: Text("This company has not provided their email ."),
duration: Duration(seconds: 2),
);
if(company.email == null){
ScaffoldMessenger.of(context).showSnackBar(emailSnack);
}else{
String email = Uri.encodeComponent(company.email!);
Uri mail = Uri.parse("mailto:${email}");
try {
await launchUrl(mail);
}
catch(e){}
}
}

Future<void> redirectSite(BuildContext context,Company company) async{
SnackBar siteSnack = SnackBar(
content: Text("This company has not provided their site ."),
duration: Duration(seconds: 2),
);
if(company.url == null){
ScaffoldMessenger.of(context).showSnackBar(siteSnack);
}
else{
String siteUrl = Uri.encodeComponent(company.url!);
Uri site = Uri.parse(siteUrl);
try {
await launchUrl(site);
}
catch(e){}

}
}


Widget buildOpenIssueList(Size size) {
return Container(
width: size.width,
Expand Down Expand Up @@ -177,7 +214,9 @@ class _CompanyDetailPageState extends State<CompanyDetailPage> {
alignment: MainAxisAlignment.start,
children: [
TextButton.icon(
onPressed: () {},
onPressed: () {
redirectEmail(context, widget.company);
},
icon: Icon(
Icons.email,
color: Colors.white,
Expand All @@ -198,7 +237,9 @@ class _CompanyDetailPageState extends State<CompanyDetailPage> {
),
),
TextButton.icon(
onPressed: () {},
onPressed: () {
redirectSite(context, widget.company);
},
icon: Icon(
Icons.public,
color: Colors.white,
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
intl: ^0.17.0
flutter_secure_storage: ^5.0.2
smooth_page_indicator: ^1.0.0+2
url_launcher: ^6.1.10
#flutter_lints: ^1.0.4

dev_dependencies:
Expand Down

0 comments on commit 93c5ff5

Please sign in to comment.