반응형
- 패키지 설치
- 터미널 설치
flutter pub add url_launcher
- android / app / src / main / AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flutter.example">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
<application
...
</application
</manifest>
- ios / Runner / Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
- 코드 예시
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
class ExamplePage extends StatefulWidget {
const ExamplePage({Key? key}) : super(key: key);
@override
State<ExamplePage> createState() => _ExamplePageState();
}
class _ExamplePageState extends State<ExamplePage> {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: Text(
"URL 열기",
),
onPressed: () {
launchUrl(Uri.parse('https://pub.dev/packages/url_launcher'));
},
),
));
}
}
참고할만한 글
반응형