Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- FutureBuilder
- Image.network
- InkWell
- AppBar
- Flutter 앱 배포
- Flutter 강좌
- ListTile
- Flutter 예제
- 반석천
- Scaffold
- sqlite
- Networking
- listview
- node.js
- flutter
- Column Widget
- Flutter Example
- MainAxisAlignment
- WillPopScope
- ListView.builder
- Row
- Snackbar
- Row Widget
- HTTP
- Load Image
- navigator
- Flutter Tutorial
- CrossAxisAlignment
- Hello World
- Cached Image
Archives
- Today
- Total
꿈꾸는 시스템 디자이너
Flutter Example - Launch Web Browser | url_launcher plugin 본문
Tutorial/Flutter with App
Flutter Example - Launch Web Browser | url_launcher plugin
독행소년 2019. 10. 23. 13:12* About plugin
https://pub.dev/packages/url_launcher
1. Add this to pubspec.yaml file
dependencies:
url_launcher: ^5.1.3
2. Source code
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
OpenWebBrowserState pageState;
class OpenWebBrowser extends StatefulWidget {
@override
OpenWebBrowserState createState() {
pageState = OpenWebBrowserState();
return pageState;
}
}
class OpenWebBrowserState extends State<OpenWebBrowser> {
final scaffoldKey = GlobalKey<ScaffoldState>();
TextEditingController teCon =
TextEditingController(text: "http://google.com");
FocusNode myFocusNode = FocusNode();
@override
void dispose() {
super.dispose();
myFocusNode.dispose();
teCon.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(title: Text("Open Web Browser")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
customButton("Google", "https://google.com"),
customButton("Flutter", "https://flutter.dev"),
customButton("Facebook", "https://facebook.com"),
Divider(color: Colors.grey, height: 50, indent: 50, endIndent: 50),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("URL: "),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: TextField(
decoration: InputDecoration(),
controller: teCon,
focusNode: myFocusNode,
),
),
),
Container(
width: 60,
child: RaisedButton(
padding: const EdgeInsets.all(0),
color: Colors.blueGrey,
textColor: Colors.white,
child: Text("lauch"),
onPressed: () {
_launchUrl(teCon.text.toString());
},
),
),
Container(
padding: const EdgeInsets.only(left: 5),
width: 65,
child: RaisedButton(
padding: const EdgeInsets.all(0),
color: Colors.grey,
textColor: Colors.white,
child: Text("clear"),
onPressed: () {
FocusScope.of(context).requestFocus(myFocusNode);
teCon.text = "http://";
},
),
)
],
),
)
],
),
),
);
}
customButton(String text, String url) {
return Container(
width: 250,
child: RaisedButton(
color: Colors.blue,
textColor: Colors.white,
child: Text(text),
onPressed: () {
teCon.text = url;
},
),
);
}
_launchUrl(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
scaffoldKey.currentState
..hideCurrentSnackBar()
..showSnackBar(
SnackBar(
content: Text("'$url' is invalid a URL"),
backgroundColor: Colors.deepOrange,
action: SnackBarAction(
label: "Done",
textColor: Colors.white,
onPressed: () {},
),
),
);
}
}
}
▶ Go to Table of Contents | 강의 목차로 이동
※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.
'Tutorial > Flutter with App' 카테고리의 다른 글
Flutter Example - How to add Admob Ad in Flutter App | firebase_admob plugin (0) | 2019.10.31 |
---|---|
Flutter Example - Http Request | Get method | http plugin (0) | 2019.10.23 |
Contents of Flutter Code Examples (0) | 2019.10.22 |
Flutter Example - Request App Review | app_review plugin (0) | 2019.10.17 |
Flutter Example - Sending simple data to other apps | flutter_share plugin (0) | 2019.10.17 |
Comments