refactor dialogs

This commit is contained in:
Fabian Freund
2026-01-19 10:54:00 +01:00
parent 8d6664c2b1
commit 3ca470d8d5
11 changed files with 312 additions and 153 deletions
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024-2025 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
/// Shows a confirmation dialog before clearing site data.
///
/// Returns true if the user confirms, false otherwise.
Future<bool?> showClearSiteDataDialog(
BuildContext context, {
required String host,
required String formattedTypes,
}) {
return showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
icon: const Icon(Icons.warning),
title: const Text('Clear Site Data'),
content: Text(
'This will clear $formattedTypes for $host.\n\n'
'You may need to log in again.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Clear'),
),
],
),
);
}
@@ -22,6 +22,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_session.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/dialogs/clear_site_data_dialog.dart';
import 'package:weblibre/utils/ui_helper.dart';
/// Section widget for clearing site data
@@ -140,26 +141,10 @@ class ClearSiteDataSection extends HookConsumerWidget {
return;
}
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
icon: const Icon(Icons.warning),
title: const Text('Clear Site Data'),
content: Text(
'This will clear ${_formatTypes(selectedTypes.value)} for ${url.host}.\n\n'
'You may need to log in again.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Clear'),
),
],
),
final confirmed = await showClearSiteDataDialog(
context,
host: url.host,
formattedTypes: _formatTypes(selectedTypes.value),
);
if (confirmed == true && context.mounted) {
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024-2025 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
/// Shows a confirmation dialog for resetting a bang's usage frequency.
///
/// Returns true if the user confirms reset, false otherwise.
Future<bool?> showResetBangDialog(
BuildContext context, {
required String triggerName,
}) {
return showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Reset usage frequency of $triggerName?'),
content: const Text('This will remove the Bang from quick select.'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Reset'),
),
],
),
);
}
@@ -47,29 +47,6 @@ class BangChips extends HookConsumerWidget {
super.key,
});
static Future<bool?> resetBangDialog(
BuildContext context,
String triggerName,
) {
return showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Reset usage frequency of $triggerName?'),
content: const Text('This will remove the Bang from quick select.'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Reset'),
),
],
),
);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final availableBangs = ref.watch(seamlessBangProvider);
@@ -29,6 +29,7 @@ import 'package:weblibre/features/bangs/domain/providers/bangs.dart';
import 'package:weblibre/features/bangs/domain/repositories/data.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/search/domain/providers/search_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/dialogs/reset_bang_dialog.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/bang_chips.dart';
class FullSearchTermSuggestions extends HookConsumerWidget {
@@ -168,9 +169,9 @@ class FullSearchTermSuggestions extends HookConsumerWidget {
.read(selectedBangTriggerProvider().notifier)
.clearTrigger();
} else {
final dialogResult = await BangChips.resetBangDialog(
final dialogResult = await showResetBangDialog(
context,
bang.trigger,
triggerName: bang.trigger,
);
if (dialogResult == true) {