How To Make Launcher URL From Flutter Android Dart

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

The URL Launcher plugin has a Launch method and it takes a string as argument containing a URL. The URL can be formatted using a number of different URL schemes. It suppors different URL schemes based on the underlying platform and installed apps in the device.

How To Make Launcher URL From Flutter Android Dart

 Launcher URL From Flutter
Step 1 
We cannot directly remove the time stamp from Launcher URL From Flutter  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 .

dev_dependencies:
  flutter_test:
    sdk: flutter
  url_launcher: ^4.1.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 Launcher URL From 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 MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  final String url = 'https://bajarangisoft.com/';

  _launchUrl() async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not lauch URL';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.red[900],
          title: Text('Launch URL From App')),
      body: Center(
          child: RaisedButton(
            onPressed: _launchUrl,
            child: Text('Goto Bajarangisoft.com'),
            color: Colors.teal,
            textColor: Colors.white,
          )),
    );
  }
}

 

Related Post