mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-23 07:19:11 +00:00
98 lines
2.7 KiB
Dart
98 lines
2.7 KiB
Dart
|
// ignore_for_file: use_build_context_synchronously
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||
|
|
||
|
import 'package:adguard_home_manager/models/server.dart';
|
||
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||
|
|
||
|
class DeleteModal extends StatelessWidget {
|
||
|
final Server serverToDelete;
|
||
|
|
||
|
const DeleteModal({
|
||
|
Key? key,
|
||
|
required this.serverToDelete,
|
||
|
}) : super(key: key);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||
|
|
||
|
void removeServer() async {
|
||
|
final deleted = await serversProvider.removeServer(serverToDelete);
|
||
|
Navigator.pop(context);
|
||
|
if (deleted == true) {
|
||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||
|
SnackBar(
|
||
|
content: Text(AppLocalizations.of(context)!.connectionRemoved),
|
||
|
backgroundColor: Colors.green,
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
else {
|
||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||
|
SnackBar(
|
||
|
content: Text(AppLocalizations.of(context)!.connectionCannotBeRemoved),
|
||
|
backgroundColor: Colors.red,
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return AlertDialog(
|
||
|
title: Column(
|
||
|
children: [
|
||
|
const Icon(
|
||
|
Icons.delete,
|
||
|
size: 26,
|
||
|
),
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.only(top: 20),
|
||
|
child: Text(
|
||
|
AppLocalizations.of(context)!.remove,
|
||
|
style: const TextStyle(
|
||
|
fontSize: 24
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
content: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: [
|
||
|
Column(
|
||
|
children: [
|
||
|
Text(
|
||
|
AppLocalizations.of(context)!.removeWarning,
|
||
|
textAlign: TextAlign.center,
|
||
|
),
|
||
|
const SizedBox(height: 10),
|
||
|
Center(
|
||
|
child: Text(
|
||
|
"${serverToDelete.connectionMethod}://${serverToDelete.domain}${serverToDelete.path ?? ""}${serverToDelete.port != null ? ':${serverToDelete.port}' : ""}",
|
||
|
style: const TextStyle(
|
||
|
fontStyle: FontStyle.italic
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
actions: [
|
||
|
TextButton(
|
||
|
onPressed: () => {
|
||
|
Navigator.pop(context)
|
||
|
},
|
||
|
child: Text(AppLocalizations.of(context)!.cancel)
|
||
|
),
|
||
|
TextButton(
|
||
|
onPressed: removeServer,
|
||
|
child: Text(AppLocalizations.of(context)!.remove),
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|