[Flutter] 플로터 뒤로 가기 버턴 구현 ( WebView )
관리자
2024-10-02 22:59
374
0
본문
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
// void main() {
// runApp(MyApp());
// }
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false, // "DEBUG" 라벨 제거
home: WebViewExample(),
));
}
class WebViewExample extends StatefulWidget {
@override
_WebViewExampleState createState() => _WebViewExampleState();
}
// class MyApp extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// title: '불교 AI',
// theme: ThemeData(
// primarySwatch: Colors.blue,
// ),
// home: WebViewExample(),
// );
// }
// }
// class _WebViewExampleState extends State<WebViewExample> {
// InAppWebViewController? webViewController;
// @override
// Widget build(BuildContext context) {
// return SafeArea(
// child: Scaffold(
// body: InAppWebView(
// initialUrlRequest: URLRequest(
// url: WebUri.uri(Uri.parse("https://seoul.ai-buddhism.com/")),
// ),
// onWebViewCreated: (controller) {
// webViewController = controller;
// },
// ),
// ),
// );
// }
// }
class _WebViewExampleState extends State<WebViewExample> {
InAppWebViewController? webViewController;
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (webViewController != null) {
bool canGoBack = await webViewController!.canGoBack();
if (canGoBack) {
webViewController!.goBack();
return false; // WebView에서 뒤로가기를 처리
}
}
return true; // 앱의 기본 뒤로 가기 처리
},
child: SafeArea(
child: Scaffold(
// appBar: AppBar(
// title: Text('불교 AI'),
// ),
body: InAppWebView(
initialUrlRequest: URLRequest(
),
onWebViewCreated: (controller) {
webViewController = controller;
},
),
),
),
);
}
}
댓글목록0
댓글 포인트 안내