diff --git a/lib/ui/widgets/fourth_screen/transaction_page.dart b/lib/ui/widgets/fourth_screen/transaction_page.dart index 15b162890cdfd3ac9e9047b00f1daa5cd7f32c01..696be8d86c39f0495e891cf9a33b4c32bcfc586e 100644 --- a/lib/ui/widgets/fourth_screen/transaction_page.dart +++ b/lib/ui/widgets/fourth_screen/transaction_page.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:backdrop/backdrop.dart'; import 'package:cron/cron.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -8,6 +7,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; +import 'package:we_slide/we_slide.dart'; import '../../../data/models/app_cubit.dart'; import '../../../data/models/node_list_cubit.dart'; @@ -22,6 +22,7 @@ import '../../logger.dart'; import '../../tutorial.dart'; import '../../tutorial_keys.dart'; import '../../ui_helpers.dart'; +import '../card_drawer.dart'; import 'fourth_tutorial.dart'; import 'transaction_item.dart'; @@ -53,6 +54,7 @@ class _TransactionsAndBalanceWidgetState final Cron cron = Cron(); static const double balanceFontSize = 36.0; late Tutorial tutorial; + late ScheduledTask scheduledTask; @override void initState() { @@ -104,10 +106,17 @@ class _TransactionsAndBalanceWidgetState _fetchPending(cursor); }); - cron.schedule(Schedule.parse(kReleaseMode ? '*/10 * * * *' : '*/5 * * * *'), - () async { + scheduledTask = cron + .schedule(Schedule.parse(kReleaseMode ? '*/10 * * * *' : '*/5 * * * *'), + () async { logger('---------- fetchTransactions via cron'); - _refresh(); + try { + _refresh(); + } catch (e) { + // TODO this should be done in main because if not this is disposed + logger('Failed via _refresh, lets try a basic fetchTransactions'); + transCubit.fetchTransactions(nodeListCubit, appCubit); + } }); tutorial = FourthTutorial(context); super.initState(); @@ -139,13 +148,16 @@ class _TransactionsAndBalanceWidgetState _pagingController.dispose(); _pendingController.dispose(); _blocListingStateSubscription.cancel(); - cron.close(); + scheduledTask.cancel(); super.dispose(); } @override Widget build(BuildContext context) { - final String myPubKey = SharedPreferencesHelper().getPubKey(); + final WeSlideController weSlideController = WeSlideController(); + final ColorScheme colorScheme = Theme.of(context).colorScheme; + const double panelMinSize = 0.0; + final double panelMaxSize = MediaQuery.of(context).size.height / 3; final bool isG1 = appCubit.currency == Currency.G1; final double currentUd = appCubit.currentUd; final String currentSymbol = currentCurrencyTrimmed(isG1); @@ -153,160 +165,196 @@ class _TransactionsAndBalanceWidgetState useSymbol: true, isG1: isG1, locale: currentLocale(context)); final bool isCurrencyBefore = isSymbolPlacementBefore(currentNumber.symbols.CURRENCY_PATTERN); - return BlocBuilder<TransactionCubit, TransactionState>( builder: (BuildContext context, TransactionState transBalanceState) { // final List<Transaction> transactions = transBalanceState.transactions; final double balance = transBalanceState.balance; + final String myPubKey = SharedPreferencesHelper().getPubKey(); + return Scaffold( + drawer: const CardDrawer(), + onDrawerChanged: (bool isOpened) { + if (isOpened && weSlideController.isOpened) { + weSlideController.hide(); + } else { + // I do here a refresh because for some reason the Consumer is not working on card change + _refresh(); + } + }, + appBar: AppBar( + title: Text(key: txMainKey, tr('transactions')), + actions: <Widget>[ + IconButton( + key: txRefreshKey, + icon: const Icon(Icons.refresh), + onPressed: () => EasyThrottle.throttle('my-throttler-refresh', + const Duration(seconds: 1), () => _refresh(), + onAfter: + () {} // <-- Optional callback, called after the duration has passed + )), + IconButton( + key: txBalanceKey, + icon: const Icon(Icons.savings), + onPressed: () => weSlideController.isOpened + ? weSlideController.hide() + : weSlideController.show()), + IconButton( + icon: const Icon(Icons.info_outline), + onPressed: () { + tutorial.showTutorial(showAlways: true); + }, + ), + const SizedBox(width: 10), + ], + ), + body: WeSlide( + controller: weSlideController, + panelMinSize: panelMinSize, + panelMaxSize: panelMaxSize, + // isDismissible: false, + body: Container( + color: colorScheme.background, + child: _transactionPanelBuilder(context, myPubKey, isG1, + currentSymbol, currentUd, isCurrencyBefore), + ), + panel: _balancePanelBuilder(colorScheme, context, isCurrencyBefore, + isG1, currentSymbol, balance, currentUd), + // This is hidden right now + panelHeader: Container( + height: panelMinSize, + color: colorScheme.secondary, + child: Center(child: Text(tr('balance'))), + ), + ), + ); + }); + } - return BackdropScaffold( - appBar: BackdropAppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: Text(tr('balance')), - actions: <Widget>[ - IconButton( - key: txRefreshKey, - icon: const Icon(Icons.refresh), - onPressed: () => EasyThrottle.throttle('my-throttler-refresh', - const Duration(seconds: 1), () => _refresh(), - onAfter: - () {} // <-- Optional callback, called after the duration has passed - )), - // const BackdropToggleButton(), - LayoutBuilder( - builder: (BuildContext lContext, - BoxConstraints constraints) => - IconButton( - key: txBalanceKey, - // icon: const Icon(Icons.account_balance_wallet), - icon: const Icon(Icons.savings), - onPressed: () { - if (Backdrop.of(lContext).isBackLayerConcealed) { - Backdrop.of(lContext).revealBackLayer(); - } else { - Backdrop.of(lContext).concealBackLayer(); - } - })), - IconButton( - icon: const Icon(Icons.info_outline), - onPressed: () { - tutorial.showTutorial(showAlways: true); - }, + Container _balancePanelBuilder( + ColorScheme colorScheme, + BuildContext context, + bool isCurrencyBefore, + bool isG1, + String currentSymbol, + double balance, + double currentUd) { + return Container( + color: colorScheme.inversePrimary, + child: Column(children: <Widget>[ + Align( + alignment: Alignment.topLeft, + child: Padding( + padding: const EdgeInsets.fromLTRB(20, 20, 20, 20), + child: Row(children: <Widget>[ + const Icon(Icons.savings), + const SizedBox(width: 30), + Text( + tr('balance'), + style: Theme.of(context).textTheme.titleLarge, + ) + ]), + )), + Expanded( + child: Scrollbar( + child: ListView( + children: <Widget>[ + Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: Center( + child: Text.rich(TextSpan( + children: <InlineSpan>[ + if (isCurrencyBefore) + currencyBalanceWidget(context, isG1, currentSymbol), + if (isCurrencyBefore) separatorSpan(), + TextSpan( + text: formatKAmountInView( + context: context, + amount: balance, + isG1: isG1, + currentUd: currentUd, + useSymbol: false), + style: TextStyle( + fontSize: balanceFontSize, + color: context.read<ThemeCubit>().isDark() + ? Colors.white + : positiveAmountColor, + fontWeight: FontWeight.bold), + ), + if (!isCurrencyBefore) separatorSpan(), + if (!isCurrencyBefore) + currencyBalanceWidget(context, isG1, currentSymbol), + ], + ))), ), - const SizedBox(width: 10), + // if (!kReleaseMode) TransactionChart(transactions: transactions) ], - ), - backLayer: Center( - child: Container( - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.inversePrimary, - border: Border.all( - color: Theme.of(context).colorScheme.inversePrimary, - width: 3), - ), - child: Scrollbar( - child: ListView( - children: <Widget>[ - Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: Center( - child: Text.rich(TextSpan( - children: <InlineSpan>[ - if (isCurrencyBefore) - currencyBalanceWidget(context, isG1, currentSymbol), - if (isCurrencyBefore) separatorSpan(), - TextSpan( - text: formatKAmountInView( - context: context, - amount: balance, - isG1: isG1, - currentUd: currentUd, - useSymbol: false), - style: TextStyle( - fontSize: balanceFontSize, - color: context.read<ThemeCubit>().isDark() - ? Colors.white - : positiveAmountColor, - fontWeight: FontWeight.bold), - ), - if (!isCurrencyBefore) separatorSpan(), - if (!isCurrencyBefore) - currencyBalanceWidget(context, isG1, currentSymbol), - ], - ))), - ), - // if (!kReleaseMode) TransactionChart(transactions: transactions) - ], - )), - )), - subHeader: BackdropSubHeader( - key: txMainKey, - title: Text(tr('transactions')), - divider: Divider( - color: Theme.of(context).colorScheme.surfaceVariant, - height: 0, + ))) + ])); + } + + RefreshIndicator _transactionPanelBuilder( + BuildContext context, + String myPubKey, + bool isG1, + String currentSymbol, + double currentUd, + bool isCurrencyBefore) { + return RefreshIndicator( + color: Colors.white, + backgroundColor: Theme.of(context).colorScheme.primary, + strokeWidth: 4.0, + onRefresh: () => _refresh(), + child: CustomScrollView( + shrinkWrap: true, + // scrollDirection: Axis.vertical, + slivers: <Widget>[ + // Some widget before all, + PagedSliverList<int, Transaction>( + shrinkWrapFirstPageIndicators: true, + pagingController: _pendingController, + builderDelegate: PagedChildBuilderDelegate<Transaction>( + animateTransitions: true, + transitionDuration: const Duration(milliseconds: 500), + itemBuilder: + (BuildContext context, Transaction tx, int index) { + return TransactionListItem( + pubKey: myPubKey, + index: index, + transaction: tx, + isG1: isG1, + currentSymbol: currentSymbol, + currentUd: currentUd, + isCurrencyBefore: isCurrencyBefore, + afterRetry: () => _refresh(), + afterCancel: () => _refresh()); + }, + noItemsFoundIndicatorBuilder: (_) => Container()), ), - ), - frontLayer: RefreshIndicator( - color: Colors.white, - backgroundColor: Theme.of(context).colorScheme.primary, - strokeWidth: 4.0, - onRefresh: () => _refresh(), - child: CustomScrollView( - shrinkWrap: true, - // scrollDirection: Axis.vertical, - slivers: <Widget>[ - // Some widget before all, - PagedSliverList<int, Transaction>( - shrinkWrapFirstPageIndicators: true, - pagingController: _pendingController, - builderDelegate: PagedChildBuilderDelegate<Transaction>( - animateTransitions: true, - transitionDuration: const Duration(milliseconds: 500), - itemBuilder: - (BuildContext context, Transaction tx, int index) { - return TransactionListItem( - pubKey: myPubKey, - index: index, - transaction: tx, - isG1: isG1, - currentSymbol: currentSymbol, - currentUd: currentUd, - isCurrencyBefore: isCurrencyBefore, - afterRetry: () => _refresh(), - afterCancel: () => _refresh()); - }, - noItemsFoundIndicatorBuilder: (_) => Container()), - ), - PagedSliverList<String?, Transaction>( - pagingController: _pagingController, - // separatorBuilder: (BuildContext context, int index) => - // const Divider(), - builderDelegate: PagedChildBuilderDelegate<Transaction>( - animateTransitions: true, - transitionDuration: const Duration(milliseconds: 500), - itemBuilder: (BuildContext context, Transaction tx, - int index) { - return TransactionListItem( - pubKey: myPubKey, - currentUd: currentUd, - isG1: isG1, - isCurrencyBefore: isCurrencyBefore, - currentSymbol: currentSymbol, - index: index + - (_pendingController.itemList != null - ? _pendingController.itemList!.length - : 0), - transaction: tx); - }, - noItemsFoundIndicatorBuilder: (_) => Padding( - padding: - const EdgeInsets.symmetric(horizontal: 20), - child: - Center(child: Text(tr('no_transactions')))))) - ]), - )); - }); + PagedSliverList<String?, Transaction>( + pagingController: _pagingController, + // separatorBuilder: (BuildContext context, int index) => + // const Divider(), + builderDelegate: PagedChildBuilderDelegate<Transaction>( + animateTransitions: true, + transitionDuration: const Duration(milliseconds: 500), + itemBuilder: + (BuildContext context, Transaction tx, int index) { + return TransactionListItem( + pubKey: myPubKey, + currentUd: currentUd, + isG1: isG1, + isCurrencyBefore: isCurrencyBefore, + currentSymbol: currentSymbol, + index: index + + (_pendingController.itemList != null + ? _pendingController.itemList!.length + : 0), + transaction: tx); + }, + noItemsFoundIndicatorBuilder: (_) => Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Center(child: Text(tr('no_transactions')))))) + ]), + ); } InlineSpan separatorSpan() {