Files
sendico/frontend/pweb/lib/pages/dashboard/dashboard.dart
2026-02-21 21:55:20 +03:00

112 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pshared/models/payment/type.dart';
import 'package:pshared/models/recipient/recipient.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pweb/models/dashboard/dashboard_payment_mode.dart';
import 'package:pweb/pages/dashboard/buttons/balance/balance.dart';
import 'package:pweb/pages/dashboard/buttons/balance/controller.dart';
import 'package:pweb/pages/dashboard/buttons/buttons.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/widgets/title.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/widget.dart';
import 'package:pweb/pages/dashboard/payouts/single/widget.dart';
import 'package:pweb/pages/loader.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class AppSpacing {
static const double small = 10;
static const double medium = 16;
static const double large = 20;
}
class DashboardPage extends StatefulWidget {
final ValueChanged<Recipient> onRecipientSelected;
final void Function(PaymentType type) onGoToPaymentWithoutRecipient;
final ValueChanged<Wallet> onTopUp;
final ValueChanged<Wallet> onWalletTap;
const DashboardPage({
super.key,
required this.onRecipientSelected,
required this.onGoToPaymentWithoutRecipient,
required this.onTopUp,
required this.onWalletTap,
});
@override
State<DashboardPage> createState() => _DashboardPageState();
}
class _DashboardPageState extends State<DashboardPage> {
DashboardPayoutMode _payoutMode = DashboardPayoutMode.single;
void _setActive(DashboardPayoutMode mode) {
setState(() {
_payoutMode = mode;
});
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final showSingle = _payoutMode == DashboardPayoutMode.single;
final showMultiple = _payoutMode == DashboardPayoutMode.multiple;
return PageViewLoader(
child: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
flex: 0,
child: TransactionRefButton(
onTap: () => _setActive(DashboardPayoutMode.single),
isActive: showSingle,
label: l10n.sendSingle,
icon: Icons.person_add,
),
),
const SizedBox(width: AppSpacing.small),
Expanded(
flex: 0,
child: TransactionRefButton(
onTap: () => _setActive(DashboardPayoutMode.multiple),
isActive: showMultiple,
label: l10n.sendMultiple,
icon: Icons.group_add,
),
),
],
),
const SizedBox(height: AppSpacing.medium),
ChangeNotifierProvider(
create: (_) => CarouselIndexController(),
child: BalanceWidget(
onTopUp: widget.onTopUp,
onWalletTap: widget.onWalletTap,
),
),
const SizedBox(height: AppSpacing.small),
if (showMultiple) TitleMultiplePayout(),
const SizedBox(height: AppSpacing.medium),
if (showSingle)
SinglePayoutForm(
onRecipientSelected: widget.onRecipientSelected,
onGoToPayment: widget.onGoToPaymentWithoutRecipient,
),
if (showMultiple) MultiplePayoutForm(),
],
),
),
),
);
}
}