refactor dialogs
This commit is contained in:
@@ -18,11 +18,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/filesystem.dart';
|
||||
import 'package:weblibre/domain/entities/profile.dart';
|
||||
import 'package:weblibre/features/user/domain/presentation/dialogs/switch_profile_dialog.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/profile.dart';
|
||||
import 'package:weblibre/utils/exit_app.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||
@@ -54,58 +53,14 @@ Future<void> handleSwitchProfile(
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
final result = await showDialog<(bool, bool)>(
|
||||
context: context,
|
||||
builder: (context) => HookBuilder(
|
||||
builder: (context) {
|
||||
final clearCache = useState(false);
|
||||
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Switch User'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Switching to User '${profile.name}' will require a restart of the Browser.",
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (duplicateMozillaProfile != null)
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: clearCache.value,
|
||||
title: const Text('Clear Shared Cache'),
|
||||
subtitle: const Text(
|
||||
'This User has been created based on an exisiting Mozilla Profile Identifier. Clearing cache will affect all linked accounts.',
|
||||
),
|
||||
onChanged: (value) {
|
||||
clearCache.value = value;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop((false, false));
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop((true, clearCache.value));
|
||||
},
|
||||
child: const Text('Switch Profile'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
final result = await showSwitchProfileDialog(
|
||||
context,
|
||||
profileName: profile.name,
|
||||
duplicateMozillaProfile: duplicateMozillaProfile,
|
||||
);
|
||||
|
||||
if (result?.$1 == true) {
|
||||
if (duplicateMozillaProfile != null && result?.$2 == true) {
|
||||
if (result?.shouldSwitch == true) {
|
||||
if (duplicateMozillaProfile != null && result?.clearCache == true) {
|
||||
await filesystem.clearMozillaProfileCache(duplicateMozillaProfile);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user