You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/modules/export_module/widgets/file_success_dialog.dart

135 lines
5.1 KiB
Dart

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:open_file/open_file.dart';
import 'package:share_plus/share_plus.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
/// Reusable success dialog for file operations (export, print, etc.)
class FileSuccessDialog {
/// Shows a success dialog with Open and Share options
///
/// [context] - The build context
/// [filePath] - Path to the successfully generated file
/// [title] - Dialog title (e.g., 'Export Successful', 'Print Successful')
/// [message] - Dialog message (e.g., 'Your file has been exported successfully')
/// [logPrefix] - Prefix for log messages (e.g., 'exported', 'printed')
static Future<void> show({
required BuildContext context,
required String filePath,
required String title,
required String message,
String logPrefix = 'file',
}) async {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext dialogContext) {
return Dialog(
backgroundColor: AppColor.background(context),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Close button
Align(
alignment: Alignment.topRight,
child: 'clear'.toSvgAsset(
color: AppColor.iconColor(context),
width: 18,
height: 18,
).onPress(() {
Navigator.of(dialogContext).pop();
}),
),
// Success icon
'done'.toSvgAsset(color: AppColor.green70, width: 56, height: 56),
const SizedBox(height: 24),
// Title
Text(
title,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppColor.headingTextColor(context),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
// Message
Text(
message,
style: TextStyle(
fontSize: 18,
color: AppColor.lightTextColor(context),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
// Action buttons
Row(
children: [
// Open button
Expanded(
child: AppFilledButton(
onPressed: () async {
log('📂 Opening $logPrefix file...');
final result = await OpenFile.open(filePath);
if (result.type != ResultType.done) {
log('⚠️ Could not open file: ${result.message}');
'No app found to open this file type. File saved to: $filePath'
.showToast;
}
},
label: 'Open',
buttonColor: AppColor.primary10,
showIcon: true,
icon: const Icon(Icons.folder_open, color: Colors.white),
height: 48,
),
),
const SizedBox(width: 12),
// Share button
Expanded(
child: AppFilledButton(
onPressed: () async {
log('📤 Sharing $logPrefix file...');
try {
final xFile = XFile(filePath);
await Share.shareXFiles(
[xFile],
text: '${title.replaceAll(' Successful', '')} file',
);
log('✅ File shared successfully');
} catch (e) {
log('❌ Error sharing file: $e');
'Failed to share file: $e'.showToast;
}
},
label: 'Share',
buttonColor: AppColor.green40,
textColor: AppColor.green60,
showIcon: true,
icon: const Icon(Icons.share, color: AppColor.green60),
height: 48,
),
),
],
),
],
),
),
);
},
);
}
}