url_launcher Package - Lets Launch URL, Send Email, Make Call or Send SMS in Flutter

This Article is posted by seven.srikanth at 7/23/2019 4:38:02 AM



<p>Hi All,font-size: 1rem;]( font-size: 1rem;](Lets see how to Launch URL, Send Email, Make Call or Send SMS in Flutter.</p> <p>Here is what you can expect from this example. ![](https://fluttercentral.com/Uploads/cd5c7eb4-d05c-4d11-9af8-bee59828b80f.gifwidth="50%height="auto](</p> <p>Add this to your dependencies in pubspec.yaml file. color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre-wrap;](color: #569cd6;](url_launcher: color: #ce9178;](any color: rgb(33, 37, 41); white-space: pre-wrap;](Here is the full code of this sample. In order to run this, copy-paste this code into main.dart file in font-size: 1rem;](your font-size: 1rem;](newly created flutter project. font-size: 1rem;]( color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre-wrap;](color: #569cd6;](import color: #ce9178;]('package:flutter/material.dart';color: #569cd6;](import color: #ce9178;]('package:url_launcher/url_launcher.dart'; color: #569cd6;](void main() => runApp(MyApp()); color: #569cd6;](class MyApp color: #569cd6;](extends StatefulWidget { color: #569cd6;](@override _MyAppState createState() => _MyAppState();} color: #569cd6;](class _MyAppState color: #569cd6;](extends State { color: #569cd6;](@override Widget build(BuildContext context) { color: #569cd6;](var title = color: #ce9178;]("UrlLauncher Demo"; color: #569cd6;](return MaterialApp( title: title, home: Scaffold( appBar: AppBar( title: Text(title), ), body: Home(), ), ); }} color: #569cd6;](class Home color: #569cd6;](extends StatelessWidget { color: #569cd6;](@override Widget build(BuildContext context) { color: #569cd6;](return Padding( padding: color: #569cd6;](const EdgeInsets.all(color: #b5cea8;](18.0), child: Center( child: Column( children: [ RaisedButton( onPressed: _launchurl, child: Text(color: #ce9178;]('Goto FlutterCentral'), ), RaisedButton( onPressed: _createEmail, child: Text(color: #ce9178;]('Email to FlutterCentral'), ), RaisedButton( onPressed: _makeCall, child: Text(color: #ce9178;]('Make a Call'), ), RaisedButton( onPressed: _sendSMS, child: Text(color: #ce9178;]('Send an SMS'), ), ], ), ), ); } color: #569cd6;](void _launchurl() color: #569cd6;](async{ color: #569cd6;](const url = color: #ce9178;]('https://fluttercentral.com'; color: #569cd6;](if(color: #569cd6;](await canLaunch(url)) { color: #569cd6;](await launch(url); } color: #569cd6;](else { color: #569cd6;](throw color: #ce9178;]('Could not launch $url'; } } color: #569cd6;](void _createEmail() color: #569cd6;](async{ color: #569cd6;](const emailaddress = color: #ce9178;]('mailto:admin@fluttercentral.com?subject=Sample Subject&body=This is a Sample email'; color: #569cd6;](if(color: #569cd6;](await canLaunch(emailaddress)) { color: #569cd6;](await launch(emailaddress); } color: #569cd6;](else { color: #569cd6;](throw color: #ce9178;]('Could not Email'; } } color: #569cd6;](void _makeCall() color: #569cd6;](async{ color: #569cd6;](const phonenumber = color: #ce9178;]("tel:9999999"; color: #569cd6;](if(color: #569cd6;](await canLaunch(phonenumber)) { color: #569cd6;](await launch(phonenumber); } color: #569cd6;](else { color: #569cd6;](throw color: #ce9178;]('Could not call'; } } color: #569cd6;](void _sendSMS() color: #569cd6;](async{ color: #569cd6;](const phonenumber = color: #ce9178;]("sms:9999999"; color: #569cd6;](if(color: #569cd6;](await canLaunch(phonenumber)) { color: #569cd6;](await launch(phonenumber); } color: #569cd6;](else { color: #569cd6;](throw color: #ce9178;]('Could not SMS'; } }}</p> <p>Hope this is helpful to you. Thanks,Srikanth</p>


Tags: How to Launch URL; How to Send Email; How to Make Call; How to Send SMS;








0 Comments
Login to comment.
Recent Comments