Newer
Older
import '../../../data/models/transaction.dart';
import '../../../data/models/transaction_cubit.dart';
class TransactionsAndBalanceWidget extends StatefulWidget {
const TransactionsAndBalanceWidget({super.key});
@override
State<TransactionsAndBalanceWidget> createState() =>
_TransactionsAndBalanceWidgetState();
}
class _TransactionsAndBalanceWidgetState
extends State<TransactionsAndBalanceWidget>
with SingleTickerProviderStateMixin {
final ScrollController _transScrollController = ScrollController();
late NodeListCubit nodeListCubit;
late TransactionsCubit transCubit;
bool isLoading = false;
// Remove in the future
transCubit = context.read<TransactionsCubit>();
nodeListCubit = context.read<NodeListCubit>();
transCubit.fetchTransactions(nodeListCubit);
_transScrollController.removeListener(_scrollListener);
_transScrollController.dispose();
if (_transScrollController.offset == 0) {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
return BlocBuilder<TransactionsCubit, TransactionsAndBalanceState>(builder:
(BuildContext context, TransactionsAndBalanceState transBalanceState) {
final List<Transaction> transactions = transBalanceState.transactions;
title: Text(tr('balance')),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
_refreshIndicatorKey.currentState?.show();
// _refreshTransactions();
},
),
icon: const Icon(Icons.savings),
onPressed: () => Backdrop.of(context).animationController,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.inversePrimary,
border: Border.all(
color: Theme.of(context).colorScheme.inversePrimary,
width: 3),
/* borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
), */
),
child: Scrollbar(
child: ListView(
// controller: scrollController,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Center(
child: Text(
formatKAmount(context, balance),
style: TextStyle(
fontSize: 36.0,
color:
balance == 0 ? Colors.lightBlue : Colors.lightBlue,
fontWeight: FontWeight.bold),
)),
subHeader: BackdropSubHeader(
title: Text(tr('transactions')),
divider: Divider(
),
frontLayer: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
/* Container(
/* color: Theme
.of(context)
.colorScheme
.surfaceVariant, */
height: 70,
width: double.infinity,
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Header(text: 'transactions'))), */
padding: const EdgeInsets.fromLTRB(0, 0, 0, 50),
child: transactions.isEmpty
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Center(child: Text(tr('no_transactions'))))
key: _refreshIndicatorKey,
color: Colors.white,
backgroundColor:
strokeWidth: 4.0,
onRefresh: () async {
return _refreshTransactions();
},
// Pull from top to show refresh indicator.
child: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
controller: _transScrollController,
itemCount: transactions.length,
// Size of elements
// itemExtent: 100,
itemBuilder: (BuildContext context, int index) {
return TransactionListItem(
index: index,
transaction: transactions[index],
);
/*
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Slidable(
// Specify a key if the Slidable is dismissible.
key: const ValueKey<int>(0),
// The end action pane is the one at the right or the bottom side.
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: <SlidableAction>[
SlidableAction(
onPressed: (BuildContext c) {
_addContact(transactions, index,
myPubKey, contactsCubit);
// FIXME i18n
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(
content:
Text(tr('contact_added')),
),
);
},
backgroundColor:
Theme.of(context).primaryColor,
foregroundColor: Colors.white,
icon: Icons.contacts,
label: tr('add_contact'),
),
],
),
child: ListTile(
title: Text(tr('transaction_from_to',
namedArgs: <String, String>{
'from': humanizeFromToPubKey(
myPubKey,
transactions[index].from),
'to': humanizeFromToPubKey(
myPubKey,
transactions[index].to)
})),
subtitle: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
if (transactions[index]
.comment
.isNotEmpty)
Text(
transactions[index].comment,
style: const TextStyle(
fontStyle: FontStyle.italic,
),
),
Text(humanizeTime(
transactions[index].time,
context.locale.toString())!)
]),
tileColor: tileColor(index, context),
trailing: Text(
'${transactions[index].amount < 0 ? "" : "+"}${(transactions[index].amount / 100).toStringAsFixed(2)} Ğ1',
style: TextStyle(
color:
transactions[index].amount <
0
? Colors.red
: Colors.blue)),
));
*/