|
|
|
|
@ -3,10 +3,13 @@ import 'dart:developer';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
|
|
|
|
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
|
|
|
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
|
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/modules/export_module/models/export_form_model.dart';
|
|
|
|
|
import 'package:test_sa/modules/export_module/models/export_module_type.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
@ -34,7 +37,7 @@ class ExportApiProvider extends ChangeNotifier {
|
|
|
|
|
// Use isDarkNotListen to safely access provider without listening
|
|
|
|
|
final backgroundColor = context.isDarkNotListen ? AppColor.containerDark : Colors.white;
|
|
|
|
|
final textColor = context.isDarkNotListen ? AppColor.white10 : AppColor.white936;
|
|
|
|
|
|
|
|
|
|
bool isPdCancel = false;
|
|
|
|
|
ProgressDialog pd = ProgressDialog(context: context);
|
|
|
|
|
pd.show(
|
|
|
|
|
max: 100,
|
|
|
|
|
@ -48,6 +51,14 @@ class ExportApiProvider extends ChangeNotifier {
|
|
|
|
|
elevation: 4,
|
|
|
|
|
msgFontSize: 14,
|
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
|
cancel: Cancel(
|
|
|
|
|
cancelClicked: () {
|
|
|
|
|
isPdCancel = true;
|
|
|
|
|
'Export Canceled'.showToast;
|
|
|
|
|
pd.close();
|
|
|
|
|
},
|
|
|
|
|
cancelImageColor: AppColor.icon2ColorNotListen(context),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
IOSink? sink;
|
|
|
|
|
@ -100,16 +111,11 @@ class ExportApiProvider extends ChangeNotifier {
|
|
|
|
|
lastProgress = progress;
|
|
|
|
|
final downloadedMB = (received / 1024 / 1024).toStringAsFixed(2);
|
|
|
|
|
final totalMB = (contentLength / 1024 / 1024).toStringAsFixed(2);
|
|
|
|
|
pd.update(
|
|
|
|
|
value: progress,
|
|
|
|
|
msg: 'Exporting: $downloadedMB MB / $totalMB MB',
|
|
|
|
|
);
|
|
|
|
|
pd.update(value: progress, msg: 'Exporting: $downloadedMB MB / $totalMB MB');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
final downloadedMB = (received / 1024 / 1024).toStringAsFixed(2);
|
|
|
|
|
pd.update(
|
|
|
|
|
msg: 'Exporting: $downloadedMB MB',
|
|
|
|
|
);
|
|
|
|
|
pd.update(msg: 'Exporting: $downloadedMB MB');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await sink.close();
|
|
|
|
|
@ -123,6 +129,9 @@ class ExportApiProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
pd.close();
|
|
|
|
|
final totalTime = DateTime.now().difference(startTime).inMilliseconds;
|
|
|
|
|
if (isPdCancel) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return filePath;
|
|
|
|
|
} else {
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
|