More split between history view and model

This commit is contained in:
poka 2021-01-30 15:48:27 +01:00
parent 267a3e0ba1
commit 82a17df414
2 changed files with 46 additions and 41 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sentry/sentry.dart' as sentry;
import 'package:qrscan/qrscan.dart' as scanner;
@ -10,6 +11,9 @@ class HistoryProvider with ChangeNotifier {
String pubkey = '';
HistoryProvider(this.pubkey);
final TextEditingController _outputPubkey = new TextEditingController();
bool isTheEnd = false;
List transBC;
// String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug
Future scan() async {
@ -105,6 +109,44 @@ class HistoryProvider with ChangeNotifier {
return transBC;
}
FetchMoreOptions checkQueryResult(result, opts) {
final List<dynamic> blockchainTX =
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
final Map pageInfo = result.data['txsHistoryBc']['both']['pageInfo'];
final String fetchMoreCursor = pageInfo['endCursor'];
if (fetchMoreCursor != null) {
opts = FetchMoreOptions(
variables: {'cursor': fetchMoreCursor},
updateQuery: (previousResultData, fetchMoreResultData) {
final List<dynamic> repos = [
...previousResultData['txsHistoryBc']['both']['edges']
as List<dynamic>,
...fetchMoreResultData['txsHistoryBc']['both']['edges']
as List<dynamic>
];
fetchMoreResultData['txsHistoryBc']['both']['edges'] = repos;
return fetchMoreResultData;
},
);
}
print(
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
if (fetchMoreCursor != null) {
transBC = parseHistory(blockchainTX);
isTheEnd = false;
} else {
print("###### DEBUG H - Début de l'historique");
isTheEnd = true;
}
return opts;
}
void resetdHistory() {
this._outputPubkey.text = '';
notifyListeners();

View File

@ -14,8 +14,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
ScrollController scrollController = ScrollController();
final nRepositories = 20;
// HistoryProvider _historyProvider;
bool isTheEnd = false;
List _transBC;
final _formKey = GlobalKey<FormState>();
FocusNode _pubkeyFocus = FocusNode();
@ -114,45 +112,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
return const Text('Aucune donnée à afficher.');
}
final List<dynamic> blockchainTX =
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
final Map pageInfo =
result.data['txsHistoryBc']['both']['pageInfo'];
final String fetchMoreCursor = pageInfo['endCursor'];
final num balance = _historyProvider
.removeDecimalZero(result.data['balance']['amount'] / 100);
if (fetchMoreCursor != null) {
opts = FetchMoreOptions(
variables: {'cursor': fetchMoreCursor},
updateQuery: (previousResultData, fetchMoreResultData) {
final List<dynamic> repos = [
...previousResultData['txsHistoryBc']['both']['edges']
as List<dynamic>,
...fetchMoreResultData['txsHistoryBc']['both']['edges']
as List<dynamic>
];
fetchMoreResultData['txsHistoryBc']['both']['edges'] = repos;
return fetchMoreResultData;
},
);
}
print(
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
if (fetchMoreCursor != null) {
_transBC = _historyProvider.parseHistory(blockchainTX);
isTheEnd = false;
} else {
print("###### DEBUG H - Début de l'historique");
isTheEnd = true;
}
// _historyProvider.resetdHistory();
opts = _historyProvider.checkQueryResult(result, opts);
// Build history list
return NotificationListener(
@ -191,7 +154,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
indent: 0,
endIndent: 0,
),
_transBC == null
_historyProvider.transBC == null
? Text('Aucune transaction à afficher.')
: loopTransactions(context, result),
],
@ -214,7 +177,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
return Column(children: <Widget>[
for (var repository in _transBC)
for (var repository in _historyProvider.transBC)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ListTile(
@ -249,7 +212,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
CircularProgressIndicator(),
],
),
if (isTheEnd)
if (_historyProvider.isTheEnd)
Column(children: <Widget>[
SizedBox(height: 15),
Text("Début de l'historique.",