flutter_launcher_plus 0.0.6 copy "flutter_launcher_plus: ^0.0.6" to clipboard
flutter_launcher_plus: ^0.0.6 copied to clipboard

Plugin to launch url and map coordinates

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_launcher_plus/flutter_launcher_plus.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  static const _channel = MethodChannel("flutter_launcher_plus");

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await FlutterLauncherPlus.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> launchUrl(String websiteUrl) async {
    await _channel
        .invokeMethod('launchUrl', <String, String>{'website_url': websiteUrl});
  }

  Future<void> drawRouteFromCurrentLocation(
      String latitude, String longitude) async {
    await _channel
        .invokeMethod('drawRouteFromCurrentLocation', <String, String>{
      'latitude': latitude,
      'longitude': longitude,
    });
  }

  Future<void> drawRouteBetweenTwoLocation(String startLatitude,
      String startLongitude, String endLatitude, String endLongitude) async {
    await _channel.invokeMethod('drawRouteBetweenTwoLocation', <String, String>{
      'startLatitude': startLatitude,
      'startLongitude': startLongitude,
      'endLatitude': endLatitude,
      'endLongitude': endLongitude,
    });
  }

  Future<void> dialNumber(String number) async {
    await _channel.invokeMethod('dialNumber', <String, String>{
      'number': number,
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initPlatformState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          alignment: Alignment.center,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("version: ${_platformVersion}"),
              ElevatedButton(
                  onPressed: () {
                    launchUrl("http://www.google.com");
                  },
                  child: Text("Launch Url")),
              ElevatedButton(
                  onPressed: () {
                    drawRouteFromCurrentLocation("28.434343", "77.33636345");
                  },
                  child: Text("Draw route from current location")),
              ElevatedButton(
                  onPressed: () {
                    drawRouteBetweenTwoLocation("25.3453535", "77.4234232",
                        "25.08274526", "77.97652464");
                  },
                  child: Text("Draw route between two locations")),
              ElevatedButton(
                  onPressed: () {
                    dialNumber("+91 9999999999");
                  },
                  child: Text("Dial Number"))
            ],
          ),
        ),
      ),
    );
  }
}
copied to clipboard
4
likes
150
points
76
downloads

Publisher

unverified uploader

Weekly Downloads

2024.08.27 - 2025.03.11

Plugin to launch url and map coordinates

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_launcher_plus