122 lines
3.7 KiB
Dart
122 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_application_1/core/theme/app_colors.dart';
|
|
|
|
class ConfirmationDialog extends StatelessWidget {
|
|
final String title;
|
|
final String message;
|
|
final String confirmText;
|
|
final String cancelText;
|
|
final bool isDestructive;
|
|
|
|
const ConfirmationDialog({
|
|
super.key,
|
|
required this.title,
|
|
required this.message,
|
|
required this.confirmText,
|
|
this.cancelText = 'Cancel',
|
|
this.isDestructive = false,
|
|
});
|
|
|
|
static Future<bool> show(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String message,
|
|
required String confirmText,
|
|
String cancelText = 'Cancel',
|
|
bool isDestructive = false,
|
|
}) async {
|
|
final result = await showDialog<bool>(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
builder: (_) => ConfirmationDialog(
|
|
title: title,
|
|
message: message,
|
|
confirmText: confirmText,
|
|
cancelText: cancelText,
|
|
isDestructive: isDestructive,
|
|
),
|
|
);
|
|
|
|
return result ?? false;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final confirmBackground = isDestructive ? AppColors.red : AppColors.primaryBlue;
|
|
|
|
return Dialog(
|
|
insetPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(28)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
fontSize: 22,
|
|
fontWeight: FontWeight.w800,
|
|
color: AppColors.textDark,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
message,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
height: 1.5,
|
|
color: AppColors.textMuted,
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
style: OutlinedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(54),
|
|
side: const BorderSide(color: AppColors.inputBorder),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(18),
|
|
),
|
|
),
|
|
child: Text(
|
|
cancelText,
|
|
style: const TextStyle(
|
|
color: AppColors.textDark,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(54),
|
|
backgroundColor: confirmBackground,
|
|
foregroundColor: AppColors.white,
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(18),
|
|
),
|
|
),
|
|
child: Text(
|
|
confirmText,
|
|
style: const TextStyle(fontWeight: FontWeight.w800),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|