usability fixes
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:qpay/config/app_config.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/models/pageable_model.dart';
|
||||
@@ -183,6 +186,58 @@ class HistoryController extends ChangeNotifier {
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
/// Builds the fully-qualified download URL for the transactions report.
|
||||
Uri _buildReportUrl({
|
||||
required String workspaceId,
|
||||
required DateTime startDate,
|
||||
required DateTime endDate,
|
||||
}) {
|
||||
final df = DateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
final start = Uri.encodeComponent(
|
||||
df.format(
|
||||
DateTime(startDate.year, startDate.month, startDate.day, 0, 0, 0),
|
||||
),
|
||||
);
|
||||
final end = Uri.encodeComponent(
|
||||
df.format(
|
||||
DateTime(endDate.year, endDate.month, endDate.day, 23, 59, 59),
|
||||
),
|
||||
);
|
||||
return Uri.parse(
|
||||
'${AppConfig.baseUrl}/public/reports/transactions/download'
|
||||
'?startDate=$start'
|
||||
'&endDate=$end'
|
||||
'&workspaceId=$workspaceId',
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens the transactions report download URL in the device browser.
|
||||
/// The browser handles the actual file download natively — no file I/O
|
||||
/// or plugin channels required, works on Android, iOS, and web.
|
||||
Future<void> downloadReport({
|
||||
required String workspaceId,
|
||||
required DateTime startDate,
|
||||
required DateTime endDate,
|
||||
}) async {
|
||||
model.isActing = true;
|
||||
_safeNotify();
|
||||
|
||||
try {
|
||||
final uri = _buildReportUrl(
|
||||
workspaceId: workspaceId,
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
);
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} catch (e) {
|
||||
logger.e('Failed to open report URL: $e');
|
||||
model.errorMessage = 'Failed to download report';
|
||||
} finally {
|
||||
model.isActing = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
void clearFilters() {
|
||||
model.statusFilter = null;
|
||||
model.typeFilter = null;
|
||||
@@ -219,4 +274,4 @@ class HistoryController extends ChangeNotifier {
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user