joaopaulofcc

Untitled

Oct 21st, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.00 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:url_launcher/url_launcher.dart';
  3. import 'package:toast/toast.dart';
  4.  
  5. void main() {
  6.   runApp(MyApp());
  7. }
  8.  
  9. class MyApp extends StatelessWidget {
  10.   @override
  11.   Widget build(BuildContext context) {
  12.     return MaterialApp(
  13.       title: 'Flutter Demo',
  14.       theme: ThemeData(
  15.         primarySwatch: Colors.blue,
  16.         visualDensity: VisualDensity.adaptivePlatformDensity,
  17.       ),
  18.       home: MyHomePage(title: 'url_laucher'),
  19.     );
  20.   }
  21. }
  22.  
  23. class MyHomePage extends StatefulWidget {
  24.   MyHomePage({Key key, this.title}) : super(key: key);
  25.  
  26.   final String title;
  27.  
  28.   @override
  29.   _MyHomePageState createState() => _MyHomePageState();
  30. }
  31.  
  32. class _MyHomePageState extends State<MyHomePage> {
  33.   abrirUrl() async {
  34.     const url = 'http://unilavras.edu.br';
  35.     if (await canLaunch(url)) {
  36.       await launch(url);
  37.     } else {
  38.       Toast.show("Não foi possível abrir o site $url", context,
  39.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  40.     }
  41.   }
  42.  
  43.   abrirWhatsApp() async {
  44.     var whatsappUrl = "whatsapp://send?phone=5535988489468&text=Olá,tudo bem?";
  45.  
  46.     if (await canLaunch(whatsappUrl)) {
  47.       await launch(whatsappUrl);
  48.     } else {
  49.       Toast.show("Não foi possível abrir o WhatsApp", context,
  50.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  51.     }
  52.   }
  53.  
  54.   abrirEmail() async {
  55.     final Uri params = Uri(
  56.       scheme: 'mailto',
  57.       path: 'joaocesar@unilavras.edu.br',
  58.       query: 'subject=Reportar&body=Detalhe aqui qual bug você encontrou: ',
  59.     );
  60.     String url = params.toString();
  61.     if (await canLaunch(url)) {
  62.       await launch(url);
  63.     } else {
  64.       Toast.show("Não foi possível abrir o cliente de email", context,
  65.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  66.     }
  67.   }
  68.  
  69.   abrirGoogleMaps() async {
  70.     const urlMap =
  71.         "https://www.google.com/maps/search/?api=1&query=-21.245138,-44.994862";
  72.     if (await canLaunch(urlMap)) {
  73.       await launch(urlMap);
  74.     } else {
  75.       Toast.show("Não foi possível abrir o Google Maps", context,
  76.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  77.     }
  78.   }
  79.  
  80.   abrirMessenger() async {
  81.     var messengerUrl = 'http://m.me/unilavras';
  82.     if (await canLaunch(messengerUrl)) {
  83.       await launch(messengerUrl);
  84.     } else {
  85.       Toast.show("Não foi possível abrir o Messenger", context,
  86.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  87.     }
  88.   }
  89.  
  90.   abrirContatos() async {
  91.     const url = 'content://com.android.contacts/contacts';
  92.     if (await canLaunch(url)) {
  93.       await launch(url);
  94.     } else {
  95.       Toast.show("Não foi possível abrir os contatos", context,
  96.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  97.     }
  98.   }
  99.  
  100.   enviarSms() async {
  101.     const url = "sms:99999999999?body=Olá, tudo bem?";
  102.     if (await canLaunch(url)) {
  103.       await launch(url);
  104.     } else {
  105.       Toast.show("Não foi possível abrir abrir o aplicativo", context,
  106.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  107.     }
  108.   }
  109.  
  110.   fazerLigacao() async {
  111.     const url = "tel:99999999999";
  112.     if (await canLaunch(url)) {
  113.       await launch(url);
  114.     } else {
  115.       Toast.show("Não foi possível abrir abrir o discador", context,
  116.           duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
  117.     }
  118.   }
  119.  
  120.   @override
  121.   Widget build(BuildContext context) {
  122.     return Scaffold(
  123.       appBar: AppBar(
  124.         title: Text(widget.title),
  125.       ),
  126.       body: Center(
  127.         child: Column(
  128.           mainAxisAlignment: MainAxisAlignment.center,
  129.           children: <Widget>[
  130.             new RaisedButton(
  131.               padding: const EdgeInsets.all(8.0),
  132.               textColor: Colors.white,
  133.               color: Colors.blue,
  134.               onPressed: () {
  135.                 abrirUrl();
  136.               },
  137.               child: new Text("Navegador"),
  138.             ),
  139.             new RaisedButton(
  140.               padding: const EdgeInsets.all(8.0),
  141.               textColor: Colors.white,
  142.               color: Colors.blue,
  143.               onPressed: () {
  144.                 abrirWhatsApp();
  145.               },
  146.               child: new Text("Whatsapp"),
  147.             ),
  148.             new RaisedButton(
  149.               padding: const EdgeInsets.all(8.0),
  150.               textColor: Colors.white,
  151.               color: Colors.blue,
  152.               onPressed: () {
  153.                 abrirEmail();
  154.               },
  155.               child: new Text("Email"),
  156.             ),
  157.             new RaisedButton(
  158.               padding: const EdgeInsets.all(8.0),
  159.               textColor: Colors.white,
  160.               color: Colors.blue,
  161.               onPressed: () {
  162.                 abrirGoogleMaps();
  163.               },
  164.               child: new Text("Mapas"),
  165.             ),
  166.             new RaisedButton(
  167.               padding: const EdgeInsets.all(8.0),
  168.               textColor: Colors.white,
  169.               color: Colors.blue,
  170.               onPressed: () {
  171.                 abrirMessenger();
  172.               },
  173.               child: new Text("Messenger"),
  174.             ),
  175.             new RaisedButton(
  176.               padding: const EdgeInsets.all(8.0),
  177.               textColor: Colors.white,
  178.               color: Colors.blue,
  179.               onPressed: () {
  180.                 abrirContatos();
  181.               },
  182.               child: new Text("Contatos"),
  183.             ),
  184.             new RaisedButton(
  185.               padding: const EdgeInsets.all(8.0),
  186.               textColor: Colors.white,
  187.               color: Colors.blue,
  188.               onPressed: () {
  189.                 enviarSms();
  190.               },
  191.               child: new Text("SMS"),
  192.             ),
  193.             new RaisedButton(
  194.               padding: const EdgeInsets.all(8.0),
  195.               textColor: Colors.white,
  196.               color: Colors.blue,
  197.               onPressed: () {
  198.                 fazerLigacao();
  199.               },
  200.               child: new Text("Telefone"),
  201.             ),
  202.           ],
  203.         ),
  204.       ),
  205.     );
  206.   }
  207. }
Add Comment
Please, Sign In to add comment