Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:url_launcher/url_launcher.dart';
- import 'package:toast/toast.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- home: MyHomePage(title: 'url_laucher'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- abrirUrl() async {
- const url = 'http://unilavras.edu.br';
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- Toast.show("Não foi possível abrir o site $url", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- abrirWhatsApp() async {
- var whatsappUrl = "whatsapp://send?phone=5535988489468&text=Olá,tudo bem?";
- if (await canLaunch(whatsappUrl)) {
- await launch(whatsappUrl);
- } else {
- Toast.show("Não foi possível abrir o WhatsApp", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- abrirEmail() async {
- final Uri params = Uri(
- scheme: 'mailto',
- path: 'joaocesar@unilavras.edu.br',
- query: 'subject=Reportar&body=Detalhe aqui qual bug você encontrou: ',
- );
- String url = params.toString();
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- Toast.show("Não foi possível abrir o cliente de email", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- abrirGoogleMaps() async {
- const urlMap =
- "https://www.google.com/maps/search/?api=1&query=-21.245138,-44.994862";
- if (await canLaunch(urlMap)) {
- await launch(urlMap);
- } else {
- Toast.show("Não foi possível abrir o Google Maps", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- abrirMessenger() async {
- var messengerUrl = 'http://m.me/unilavras';
- if (await canLaunch(messengerUrl)) {
- await launch(messengerUrl);
- } else {
- Toast.show("Não foi possível abrir o Messenger", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- abrirContatos() async {
- const url = 'content://com.android.contacts/contacts';
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- Toast.show("Não foi possível abrir os contatos", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- enviarSms() async {
- const url = "sms:99999999999?body=Olá, tudo bem?";
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- Toast.show("Não foi possível abrir abrir o aplicativo", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- fazerLigacao() async {
- const url = "tel:99999999999";
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- Toast.show("Não foi possível abrir abrir o discador", context,
- duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(widget.title),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirUrl();
- },
- child: new Text("Navegador"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirWhatsApp();
- },
- child: new Text("Whatsapp"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirEmail();
- },
- child: new Text("Email"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirGoogleMaps();
- },
- child: new Text("Mapas"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirMessenger();
- },
- child: new Text("Messenger"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- abrirContatos();
- },
- child: new Text("Contatos"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- enviarSms();
- },
- child: new Text("SMS"),
- ),
- new RaisedButton(
- padding: const EdgeInsets.all(8.0),
- textColor: Colors.white,
- color: Colors.blue,
- onPressed: () {
- fazerLigacao();
- },
- child: new Text("Telefone"),
- ),
- ],
- ),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment