https://totally-developer.tistory.com/157
플러터 웹뷰 설정
pubspec.yaml
파일dependencies:
flutter:
sdk: flutter
webview_flutter: ^4.0.1
cupertino_icons: ^1.0.6
main.dart
)dart코드 복사
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'UI Program List',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ProgramListScreen(),
);
}
}
class ProgramListScreen extends StatelessWidget {
final List<Program> programs = [
Program(name: 'WebView', description: 'View web content', icon: Icons.web)
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('UI Program List'),
),
body: ListView.builder(
itemCount: programs.length,
itemBuilder: (context, index) {
final program = programs[index];
return ListTile(
leading: Icon(program.icon),
title: Text(program.name),
subtitle: Text(program.description),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
if (program.name == 'WebView') {
return WebViewExample();
}
// 다른 프로그램에 대한 네비게이션 추가
return Container(); // 기본 반환값
},
),
);
},
);
},
),
);
}
}
class WebViewExample extends StatefulWidget {
@override
_WebViewExampleState createState() => _WebViewExampleState();
}
class _WebViewExampleState extends State<WebViewExample> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('<https://flutter.dev>'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('WebView Example'),
),
body: WebViewWidget(controller: _controller),
);
}
}
class Program {
final String name;
final String description;
final IconData icon;
Program({required this.name, required this.description, required this.icon});
}
WebViewController
를 초기화하고 JavaScript를 활성화합니다.WebView
대신 WebViewWidget
을 사용하여 웹 콘텐츠를 표시합니다.android/app/src/main/AndroidManifest.xml
파일에 인터넷 권한을 추가합니다.
xml코드 복사
<uses-permission android:name="android.permission.INTERNET"/>
ios/Runner/Info.plist
파일에 다음 내용을 추가합니다.
xml코드 복사
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>