How To Make Url Launcher Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

URL launcher is used to open websites, create a email, send a sms and also can make a call.We use them in our applications every now and then.Now a days every app will notify the user with the task updates using sms and email’s.We can integrate sms and email within the app to send them directly to users.

How To Make Url Launcher Using Flutter Android App

Url Launcher
Step 1 
We cannot directly remove the time stamp from Url Launcher but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .

dependencies:
  flutter:
    sdk: flutter
  url_launcher: 5.5.0

Step 2
After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command.

flutter pub get



Complete Code For Url Launcher In Flutter
main.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {runApp(
    new MyApp(),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      home: new Home(),
    );
  }
}

class Home extends StatelessWidget {
  Home({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) =>
      new Scaffold(
        appBar: new AppBar(
          backgroundColor: Colors.deepPurple,
          title: new Text(" Url Launchers"),
        ),
        body: new Center(
          child: Padding(
            padding: const EdgeInsets.all(20.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Card(
                  color: Colors.white70,
                  shape: RoundedRectangleBorder(
                    side: new BorderSide(color: Colors.white, width: 2.0),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Padding(
                          padding: const EdgeInsets.all(20.0),
                          child: FlatButton.icon(
                            icon: Icon(Icons.add_to_home_screen),
                            label: Text(
                              "Open Website"),
                            onPressed: () => launch("http://google.com"),
                          )
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 10.0),
                Card(
                  shape: RoundedRectangleBorder(
                    side: new BorderSide(color: Colors.white, width: 2.0),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: FlatButton.icon(
                          icon: Icon(Icons.call),
                          label:Text(
                            "Make a Call",),
                          onPressed: () => launch("tel://123"),
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 10.0),
                Card(
                  color: Colors.white70,
                  shape: RoundedRectangleBorder(
                    side: new BorderSide(color: Colors.white, width: 2.0),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: FlatButton.icon(
                          icon: Icon(Icons.email),
                          label:Text(
                              "Send a Email"),
                          onPressed: () =>
                              launch(
                                  "mailto:https://bajarangisoft.com/blog/"),
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 10.0),
                Card(
                  shape: RoundedRectangleBorder(
                    side: new BorderSide(color: Colors.white, width: 2.0),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.all(20.0),
                        child:  FlatButton.icon(
                          icon: Icon(Icons.sms),
                          label:Text(
                              "Write a SMS"),
                          onPressed: () => launch("sms:123456789"),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      );
}

 

Related Post