Below example will help you to create a Webview in Flutter, which will load on a Button click.
Thanks,
The final App output is going to look as below,
Once the New Project is created you need to add the below flutter_webview_plugin package into the pubspec.yaml file.
flutter_webview_plugin: ^0.3.0+2
And then Save to get the Packages.
One the Packages are updated, add the below code to your main.dart code file in lib folder and run the program.
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var title = 'Webview Demo';
return new MaterialApp(
title: title,
routes: {
'/widget': (_) => new WebviewScaffold(
url: "https:\\FlutterCentral.com",
appBar: new AppBar(
title: const Text('Widget Webview'),
),
withZoom: false,
withLocalStorage: true,
)
},
home: new MyAppHomePage(),
);
}
}
class MyAppHomePage extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyAppHomePage> {
void _opennewpage() {
Navigator.of(context).pushNamed('/widget');
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Sample App"),
),
body: new Center(
child: new RaisedButton(
child: Text('Open Link'),
onPressed: () {
_opennewpage();
}
) ,
)
);
}
}
Hope this is helpful.
Srikanth
Related Articles:
-> Move to next Tab on Button Click in Flutter https://fluttercentral.com/Articles/Post/1054 ;
-> List of Cards from a JSON source in Flutter https://fluttercentral.com/Articles/Post/55
-> SliverAppBar Widget in Flutter https://fluttercentral.com/Articles/Post/51
-> Flutter Stepper Widget - Change State in Response to Input https://fluttercentral.com/Articles/Post/44