bringing account dataconnect
This commit is contained in:
@@ -1,111 +1,165 @@
|
|||||||
import 'package:core_localization/core_localization.dart';
|
import 'package:core_localization/core_localization.dart';
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:firebase_data_connect/firebase_data_connect.dart' as fdc;
|
||||||
|
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||||
|
|
||||||
/// Card showing the current payment method.
|
/// Card showing the current payment method.
|
||||||
class PaymentMethodCard extends StatelessWidget {
|
class PaymentMethodCard extends StatefulWidget {
|
||||||
/// Creates a [PaymentMethodCard].
|
/// Creates a [PaymentMethodCard].
|
||||||
const PaymentMethodCard({super.key});
|
const PaymentMethodCard({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PaymentMethodCard> createState() => _PaymentMethodCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PaymentMethodCardState extends State<PaymentMethodCard> {
|
||||||
|
late final Future<dc.GetAccountsByOwnerIdData?> _accountsFuture =
|
||||||
|
_loadAccounts();
|
||||||
|
|
||||||
|
Future<dc.GetAccountsByOwnerIdData?> _loadAccounts() async {
|
||||||
|
final String? businessId =
|
||||||
|
dc.ClientSessionStore.instance.session?.business?.id;
|
||||||
|
if (businessId == null || businessId.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final fdc.QueryResult<dc.GetAccountsByOwnerIdData,
|
||||||
|
dc.GetAccountsByOwnerIdVariables> result =
|
||||||
|
await dc.ExampleConnector.instance
|
||||||
|
.getAccountsByOwnerId(ownerId: businessId)
|
||||||
|
.execute();
|
||||||
|
return result.data;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return FutureBuilder<dc.GetAccountsByOwnerIdData?>(
|
||||||
padding: const EdgeInsets.all(UiConstants.space4),
|
future: _accountsFuture,
|
||||||
decoration: BoxDecoration(
|
builder: (BuildContext context,
|
||||||
color: UiColors.white,
|
AsyncSnapshot<dc.GetAccountsByOwnerIdData?> snapshot) {
|
||||||
borderRadius: UiConstants.radiusLg,
|
final List<dc.GetAccountsByOwnerIdAccounts> accounts =
|
||||||
border: Border.all(color: UiColors.border),
|
snapshot.data?.accounts ??
|
||||||
boxShadow: <BoxShadow>[
|
<dc.GetAccountsByOwnerIdAccounts>[];
|
||||||
BoxShadow(
|
final dc.GetAccountsByOwnerIdAccounts? account =
|
||||||
color: UiColors.black.withValues(alpha: 0.04),
|
accounts.isNotEmpty ? accounts.first : null;
|
||||||
blurRadius: 8,
|
final String bankLabel =
|
||||||
offset: const Offset(0, 2),
|
account?.bank.isNotEmpty == true ? account!.bank : '----';
|
||||||
),
|
final String last4 =
|
||||||
],
|
account?.last4.isNotEmpty == true ? account!.last4 : '----';
|
||||||
),
|
final bool isPrimary = account?.isPrimary ?? false;
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
return Container(
|
||||||
Row(
|
padding: const EdgeInsets.all(UiConstants.space4),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
decoration: BoxDecoration(
|
||||||
children: <Widget>[
|
color: UiColors.white,
|
||||||
Text(
|
borderRadius: UiConstants.radiusLg,
|
||||||
t.client_billing.payment_method,
|
border: Border.all(color: UiColors.border),
|
||||||
style: UiTypography.title2b.textPrimary,
|
boxShadow: <BoxShadow>[
|
||||||
),
|
BoxShadow(
|
||||||
GestureDetector(
|
color: UiColors.black.withValues(alpha: 0.04),
|
||||||
onTap: () {},
|
blurRadius: 8,
|
||||||
child: Row(
|
offset: const Offset(0, 2),
|
||||||
children: <Widget>[
|
|
||||||
const Icon(UiIcons.add, size: 14, color: UiColors.primary),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(
|
|
||||||
t.client_billing.add_payment,
|
|
||||||
style: UiTypography.footnote2b.textPrimary,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: UiConstants.space3),
|
child: Column(
|
||||||
Container(
|
children: <Widget>[
|
||||||
padding: const EdgeInsets.all(UiConstants.space3),
|
Row(
|
||||||
decoration: BoxDecoration(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
color: UiColors.bgSecondary,
|
children: <Widget>[
|
||||||
borderRadius: UiConstants.radiusMd,
|
Text(
|
||||||
),
|
t.client_billing.payment_method,
|
||||||
child: Row(
|
style: UiTypography.title2b.textPrimary,
|
||||||
children: <Widget>[
|
|
||||||
Container(
|
|
||||||
width: 40,
|
|
||||||
height: 28,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: UiColors.primary,
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
),
|
||||||
child: const Center(
|
GestureDetector(
|
||||||
child: Text(
|
onTap: () {},
|
||||||
'VISA',
|
child: Row(
|
||||||
style: TextStyle(
|
children: <Widget>[
|
||||||
color: UiColors.white,
|
const Icon(
|
||||||
fontSize: 10,
|
UiIcons.add,
|
||||||
fontWeight: FontWeight.bold,
|
size: 14,
|
||||||
),
|
color: UiColors.primary,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
t.client_billing.add_payment,
|
||||||
|
style: UiTypography.footnote2b.textPrimary,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(width: UiConstants.space3),
|
),
|
||||||
Expanded(
|
if (account != null) ...<Widget>[
|
||||||
child: Column(
|
const SizedBox(height: UiConstants.space3),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Container(
|
||||||
|
padding: const EdgeInsets.all(UiConstants.space3),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: UiColors.bgSecondary,
|
||||||
|
borderRadius: UiConstants.radiusMd,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('•••• 4242', style: UiTypography.body2b.textPrimary),
|
Container(
|
||||||
Text(
|
width: 40,
|
||||||
t.client_billing.expires(date: '12/25'),
|
height: 28,
|
||||||
style: UiTypography.footnote2r.textSecondary,
|
decoration: BoxDecoration(
|
||||||
|
color: UiColors.primary,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
bankLabel,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: UiColors.white,
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: UiConstants.space3),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
'•••• $last4',
|
||||||
|
style: UiTypography.body2b.textPrimary,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
t.client_billing.expires(date: '12/25'),
|
||||||
|
style: UiTypography.footnote2r.textSecondary,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (isPrimary)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: UiColors.accent,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
t.client_billing.default_badge,
|
||||||
|
style: UiTypography.titleUppercase4b.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 6,
|
|
||||||
vertical: 2,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: UiColors.accent,
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
t.client_billing.default_badge,
|
|
||||||
style: UiTypography.titleUppercase4b.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user