Skip to content

closeCustomTabs() does not close minimized browser tab — Need support for closing or hiding minimized tabs #270

@GowthamanRavichandran3

Description

@GowthamanRavichandran3

I'm facing an issue with closing a browser tab that is launched using a custom URL and then minimized.

Problem Description:
I launch a browser tab with a URL, and after launching, I minimize the browser window. When I try to close this tab using await closeCustomTabs();, it does not close the minimized tab as expected. For my use case, the tab should be closed regardless of its state (minimized or active).

Expected Behavior:
Calling await closeCustomTabs(); should close the tab even if it is in a minimized state.

Actual Behavior:
The tab remains open if it was minimized, and does not close as expected.

Questions:

  1. Is there a workaround or alternate method to ensure the minimized tab can be closed?
  2. If not possible to close it, is there a way to hide or disable the minimize icon/button, so the user cannot minimize the tab in the first place?

Steps to Reproduce:

  • Run the below sample code on an Android device.
  • Tap the "Open Google" button to launch the custom tab.
  • Minimize the opened browser tab.
  • Tap the "Close Custom Tab" button in the app.

Code sample:

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Custom Tabs Example',
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

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

  Future<void> _launchGoogle(BuildContext context) async {
    final theme = Theme.of(context);
    try {
      await launchUrl(
        Uri.parse('https://google.com'),
        customTabsOptions: CustomTabsOptions(
          colorSchemes: CustomTabsColorSchemes.defaults(
            toolbarColor: theme.colorScheme.surface,
          ),
          showTitle: true,
          urlBarHidingEnabled: true,
        ),
        safariVCOptions: SafariViewControllerOptions(
          preferredBarTintColor: theme.colorScheme.surface,
          preferredControlTintColor: theme.colorScheme.onSurface,
          barCollapsingEnabled: true,
        ),
      );
    } catch (e) {
      debugPrint('Failed to launch URL: $e');
    }
  }

  Future<void> _closeCustomTabs() async {
    try {
      await closeCustomTabs();
    } catch (e) {
      debugPrint('Failed to close custom tab: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Custom Tabs Example')),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            FilledButton(
              onPressed: () => _launchGoogle(context),
              child: const Text('Open Google'),
            ),
            const SizedBox(height: 16),
            FilledButton(
              onPressed: () async {
                await _closeCustomTabs();
              },
              child: const Text('Close Custom Tab'),
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions