fix: use different pageInfo on activityscreen when pop multiple accounts

This commit is contained in:
poka 2023-03-15 22:57:30 +01:00
parent c6a7474c78
commit 5ab9377f82
3 changed files with 148 additions and 112 deletions

View File

@ -1,13 +1,14 @@
// ignore_for_file: must_be_immutable
import 'package:easy_localization/easy_localization.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/duniter_indexer.dart';
import 'package:gecko/widgets/bottom_app_bar.dart';
import 'package:gecko/widgets/header_profile.dart';
import 'package:gecko/widgets/history_query.dart';
import 'package:provider/provider.dart';
class ActivityScreen extends StatelessWidget with ChangeNotifier {
ActivityScreen({required this.address, required this.avatar, this.username})
@ -18,19 +19,35 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 60 * ratio,
title: SizedBox(
height: 22,
child: Text('accountActivity'.tr()),
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: true);
return WillPopScope(
onWillPop: () {
duniterIndexer.fetchMoreCursor =
duniterIndexer.pageInfo = duniterIndexer.transBC = null;
return Future<bool>.value(true);
},
child: Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 60 * ratio,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () {
duniterIndexer.fetchMoreCursor =
duniterIndexer.pageInfo = duniterIndexer.transBC = null;
Navigator.of(context).pop();
}),
title: SizedBox(
height: 22,
child: Text('accountActivity'.tr()),
),
),
),
bottomNavigationBar: const GeckoBottomAppBar(),
body: Column(children: <Widget>[
HeaderProfile(address: address, username: username),
HistoryQuery(address: address),
]));
bottomNavigationBar: const GeckoBottomAppBar(),
body: Column(children: <Widget>[
HeaderProfile(address: address, username: username),
HistoryQuery(address: address),
])),
);
}
}

View File

@ -4,7 +4,7 @@ import 'package:gecko/globals.dart';
import 'package:gecko/models/queries_indexer.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/duniter_indexer.dart';
import 'package:gecko/widgets/transaction_tile.dart';
import 'package:gecko/widgets/history_view.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart';
@ -116,11 +116,14 @@ class HistoryQuery extends StatelessWidget {
child: ListView(
key: keyListTransactions,
controller: scrollController,
children: <Widget>[historyView(context, result)],
children: <Widget>[HistoryView(result: result)],
),
),
),
onNotification: (dynamic t) {
if (duniterIndexer.pageInfo == null) {
duniterIndexer.reload();
}
if (t is ScrollEndNotification &&
scrollController.position.pixels >=
scrollController.position.maxScrollExtent * 0.7 &&
@ -136,100 +139,4 @@ class HistoryQuery extends StatelessWidget {
)),
);
}
Widget historyView(context, result) {
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
int keyID = 0;
const double avatarSize = 200;
bool isMigrationPassed = false;
List<String> pastDelimiters = [];
return duniterIndexer.transBC == null
? Column(children: <Widget>[
const SizedBox(height: 50),
Text(
"noTransactionToDisplay".tr(),
style: const TextStyle(fontSize: 18),
)
])
: Column(children: <Widget>[
Column(
children: duniterIndexer.transBC!.map((repository) {
final answer = computeHistoryView(repository);
pastDelimiters.add(answer['dateDelimiter']);
bool isMigrationTime = false;
if (answer['isMigrationTime'] && !isMigrationPassed) {
isMigrationPassed = true;
isMigrationTime = true;
}
return Column(children: <Widget>[
if (isMigrationTime)
Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Image(
image: AssetImage('assets/party.png'), height: 40),
const SizedBox(width: 40),
Text(
'blockchainStart'.tr(),
style: const TextStyle(
fontSize: 25,
color: Colors.blueAccent,
fontWeight: FontWeight.w500),
),
const SizedBox(width: 40),
const Image(
image: AssetImage('assets/party.png'), height: 40),
],
),
),
// if ((countsDelimiter[answer['dateDelimiter']] ?? 0) >= 1)
if (pastDelimiters.length == 1 ||
pastDelimiters.length >= 2 &&
!(pastDelimiters[pastDelimiters.length - 2] ==
answer['dateDelimiter']))
Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: Text(
answer['dateDelimiter'],
style: const TextStyle(
fontSize: 23,
color: orangeC,
fontWeight: FontWeight.w300),
),
),
TransactionTile(
keyID: keyID,
avatarSize: avatarSize,
repository: repository,
dateForm: answer['dateForm'],
finalAmount: answer['finalAmount'],
duniterIndexer: duniterIndexer,
context: context),
]);
}).toList()),
if (result.isLoading && duniterIndexer.pageInfo!['hasPreviousPage'])
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
CircularProgressIndicator(),
],
),
if (!duniterIndexer.pageInfo!['hasNextPage'])
Column(
children: <Widget>[
const SizedBox(height: 15),
Text("historyStart".tr(),
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20)),
const SizedBox(height: 15)
],
)
]);
}
}

View File

@ -0,0 +1,112 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/duniter_indexer.dart';
import 'package:gecko/widgets/transaction_tile.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart';
class HistoryView extends StatelessWidget {
const HistoryView({
Key? key,
required this.result,
}) : super(key: key);
final QueryResult result;
@override
Widget build(BuildContext context) {
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
int keyID = 0;
const double avatarSize = 200;
bool isMigrationPassed = false;
List<String> pastDelimiters = [];
return duniterIndexer.transBC == null
? Column(children: <Widget>[
const SizedBox(height: 50),
Text(
"noTransactionToDisplay".tr(),
style: const TextStyle(fontSize: 18),
)
])
: Column(children: <Widget>[
Column(
children: duniterIndexer.transBC!.map((repository) {
final answer = computeHistoryView(repository);
pastDelimiters.add(answer['dateDelimiter']);
bool isMigrationTime = false;
if (answer['isMigrationTime'] && !isMigrationPassed) {
isMigrationPassed = true;
isMigrationTime = true;
}
return Column(children: <Widget>[
if (isMigrationTime)
Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Image(
image: AssetImage('assets/party.png'), height: 40),
const SizedBox(width: 40),
Text(
'blockchainStart'.tr(),
style: const TextStyle(
fontSize: 25,
color: Colors.blueAccent,
fontWeight: FontWeight.w500),
),
const SizedBox(width: 40),
const Image(
image: AssetImage('assets/party.png'), height: 40),
],
),
),
// if ((countsDelimiter[answer['dateDelimiter']] ?? 0) >= 1)
if (pastDelimiters.length == 1 ||
pastDelimiters.length >= 2 &&
!(pastDelimiters[pastDelimiters.length - 2] ==
answer['dateDelimiter']))
Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: Text(
answer['dateDelimiter'],
style: const TextStyle(
fontSize: 23,
color: orangeC,
fontWeight: FontWeight.w300),
),
),
TransactionTile(
keyID: keyID,
avatarSize: avatarSize,
repository: repository,
dateForm: answer['dateForm'],
finalAmount: answer['finalAmount'],
duniterIndexer: duniterIndexer,
context: context),
]);
}).toList()),
if (result.isLoading && duniterIndexer.pageInfo!['hasPreviousPage'])
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
CircularProgressIndicator(),
],
),
if (!duniterIndexer.pageInfo!['hasNextPage'])
Column(
children: <Widget>[
const SizedBox(height: 15),
Text("historyStart".tr(),
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20)),
const SizedBox(height: 15)
],
)
]);
}
}