open_browser 0.0.2 copy "open_browser: ^0.0.2" to clipboard
open_browser: ^0.0.2 copied to clipboard

Plugin to open browser

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:open_browser/open_webview.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';
  final _openWebviewPlugin = OpenWebview();

  TextEditingController urlController = TextEditingController();

  final _formKey = GlobalKey<FormState>();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion =
          await _openWebviewPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child:Padding(
            padding: EdgeInsets.all(20),
            child:Form(
              key: _formKey,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  TextFormField(
                    controller: urlController,
                    validator: (value){
                      if(value == null || value.isEmpty){
                        return 'Please enter valid url';
                      }
                      return null;
                    },
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 15
                    ),
                    decoration: InputDecoration(
                        hintStyle: TextStyle(color: Colors.grey,fontSize:15),
                        hintText: 'Please enter/paste your url here'
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(
                        textStyle: const TextStyle(fontSize: 20)),
                    child: Text("Open Webview"),
                      onPressed: (){
                        if(_formKey.currentState!.validate()){
                          openWebviewFromApp();
                        }
                      }
                  )
                ],
              ),
            )
          )
        ),
      ),
    );
  }

  Future<dynamic> openWebviewFromApp() async{
   // String url = "https://www.infosys.com/";
    String url = urlController.text.toString();
    var result = await _openWebviewPlugin.openBrowser(url);
  }
}
0
likes
130
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

Plugin to open browser

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on open_browser