pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.28k stars 1.61k forks source link

The ChromeSafariBrowser's browser.close() method is not working as expected. #2270

Open ivaldo opened 1 month ago

ivaldo commented 1 month ago

I'm encountering an issue with the ChromeSafariBrowser plugin where the browser.close() method is failing to close the browser window.

I'm utilizing 'ChromeSafariBrowser' from the 'flutter_inappview 6.0.0' package. After initiating a new browser window using browser.open() and subsequently attempting to close it after a timed interval via browser.close(), the browser window persists, obstructing the normal progression of my application.

Environment

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, 3.15.0-15.2.pre, on Linux Mint 22 6.8.0-41-generic, locale pt_BR.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2024.1) [✓] IntelliJ IDEA Community Edition (version 2024.1) [✓] VS Code (version 1.93.0) [✓] Connected device (3 available) [✓] Network resources

Steps to reproduce

main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

void main() {
  runApp(const MyApp());
}

class MyChromeSafariBrowser extends ChromeSafariBrowser {
  MyChromeSafariBrowser() : super();

  @override
  void onOpened() {
    debugPrint('ChromeSafariBrowser opened');
  }

  @override
  void onCompletedInitialLoad(bool? didLoadSuccessfully) {}

  @override
  void onClosed() {
    debugPrint('ChromeSafariBrowser closed');
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ChromeSafariBrowser browser = MyChromeSafariBrowser();

  void open() async {
    await browser.open(
      url: WebUri("https://www.google.com"),
      settings: ChromeSafariBrowserSettings(
        isSingleInstance: false,
        showTitle: false,
        enableUrlBarHiding: true,
        isTrustedWebActivity: true,
      ),
    );
    var timer = Timer(Duration(seconds: 5), () async {
      await browser.close();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FloatingActionButton(
              onPressed: open,
              child: const Icon(Icons.add),
            ),
            SizedBox(
              width: 20,
            ),
          ],
        ),
      ),
    );
  }
}

pubspec.yaml

name: flutter_browser
description: "A new Flutter project."
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: '>=3.2.0-134.1.beta <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  flutter_inappwebview: ^6.0.0
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
flutter:
  uses-material-design: true

Log

I/Timeline(20846): Timeline: Activity_launch_request time:237940639
W/ActivityThread(20846): handleWindowVisibility: no activity for token android.os.BinderProxy@b25873a
D/ForceDarkHelper(20846): updateByCheckExcludeList: pkg: com.example.flutter_browser activity: com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.TrustedWebActivity@4d7148
I/chatty  (20846): uid=10559(com.example.flutter_browser) identical 2 lines
D/ForceDarkHelper(20846): updateByCheckExcludeList: pkg: com.example.flutter_browser activity: com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.TrustedWebActivity@4d7148
I/Timeline(20846): Timeline: Activity_launch_request time:237940712
I/flutter (20846): ChromeSafariBrowser opened
I/Timeline(20846): Timeline: Activity_launch_request time:237945718
I/flutter (20846): ChromeSafariBrowser closed
github-actions[bot] commented 1 month ago

👋 @ivaldo

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!