85 lines
2.4 KiB
Dart
85 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:pshared/provider/payment/payments.dart';
|
|
|
|
import 'package:pweb/app/router/payout_routes.dart';
|
|
import 'package:pweb/controllers/payment_details.dart';
|
|
import 'package:pweb/pages/report/details/content.dart';
|
|
import 'package:pweb/pages/report/details/states/error.dart';
|
|
import 'package:pweb/pages/report/details/states/not_found.dart';
|
|
import 'package:pweb/utils/report/download_act.dart';
|
|
|
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
|
|
|
|
class PaymentDetailsPage extends StatelessWidget {
|
|
final String paymentId;
|
|
|
|
const PaymentDetailsPage({
|
|
super.key,
|
|
required this.paymentId,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ChangeNotifierProxyProvider<PaymentsProvider, PaymentDetailsController>(
|
|
create: (_) => PaymentDetailsController(paymentId: paymentId),
|
|
update: (_, payments, controller) => controller!
|
|
..update(payments, paymentId),
|
|
child: const _PaymentDetailsView(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PaymentDetailsView extends StatelessWidget {
|
|
const _PaymentDetailsView();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Consumer<PaymentDetailsController>(
|
|
builder: (context, controller, child) {
|
|
final loc = AppLocalizations.of(context)!;
|
|
if (controller.isLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
if (controller.error != null) {
|
|
return PaymentDetailsError(
|
|
message: controller.error?.toString() ?? loc.noErrorInformation,
|
|
onRetry: () => controller.refresh(),
|
|
);
|
|
}
|
|
|
|
final payment = controller.payment;
|
|
if (payment == null) {
|
|
return PaymentDetailsNotFound(onBack: () => _handleBack(context));
|
|
}
|
|
|
|
return PaymentDetailsContent(
|
|
payment: payment,
|
|
onBack: () => _handleBack(context),
|
|
onDownloadAct: controller.canDownload
|
|
? () => downloadPaymentAct(context, payment.paymentRef ?? '')
|
|
: null,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
void _handleBack(BuildContext context) {
|
|
final router = GoRouter.of(context);
|
|
if (router.canPop()) {
|
|
context.pop();
|
|
return;
|
|
}
|
|
context.go(PayoutRoutes.reportsPath);
|
|
}
|
|
}
|