플로터 뒤로 가기 버턴 구현 ( WebView ) > 안드로이드

본문 바로가기

안드로이드

마이홈
쪽지
맞팔친구
팔로워
팔로잉
스크랩
TOP
DOWN

[Flutter] 플로터 뒤로 가기 버턴 구현 ( WebView )

profile_image
관리자
2024-10-02 22:59 61 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(
              url: WebUri.uri(Uri.parse("https://seoul.ai-buddhism.com/")),
            ),
            onWebViewCreated: (controller) {
              webViewController = controller;
            },
          ),
        ),
      ),
    );
  }
}

댓글목록0

등록된 댓글이 없습니다.

댓글쓰기

적용하기
자동등록방지 숫자를 순서대로 입력하세요.
게시판 전체검색