closeCustomTabs() does not close minimized browser tab — Need support for closing or hiding minimized tabs
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:
- Is there a workaround or alternate method to ensure the minimized tab can be closed?
- 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'),
),
],
),
),
);
}
}
Unfortunately, this issue cannot be resolved by the plugin at this time.
- Is there a workaround or alternate method to ensure the minimized tab can be closed?
Due to Android's specifications, there is no known workaround. Custom Tabs are actually external apps, and there is no API provided to control or close minimized (PIP) external apps. So currently, it is not possible.
- 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?
Currently, Custom Tabs do not provide such an option. If this option is added in the future, I would like to support it in this plugin as well.