Provider for history is OK; fetchmore for GVA infinitescroll is OK but seems to have bugs;

This commit is contained in:
poka 2021-01-24 08:53:03 +01:00
parent a4b0a099ff
commit 5542a8eea8
4 changed files with 119 additions and 96 deletions

View File

@ -96,12 +96,14 @@ class Gecko extends StatelessWidget {
); );
DubpRust.setup(); DubpRust.setup();
return MultiProvider( return
providers: [ // MultiProvider(
Provider(create: (context) => HistoryProvider()), // providers: [
Provider(create: (context) => MyWalletsProvider()), // Provider(create: (context) => HistoryProvider()),
], // Provider(create: (context) => MyWalletsProvider()),
child: MaterialApp( // ],
// child:
MaterialApp(
title: 'Ğecko', title: 'Ğecko',
theme: ThemeData( theme: ThemeData(
primaryColor: Color(0xffFFD58D), primaryColor: Color(0xffFFD58D),
@ -114,7 +116,13 @@ class Gecko extends StatelessWidget {
// displayColor: Colors.blue, // displayColor: Colors.blue,
), ),
), ),
home: GraphQLProvider( home: MultiProvider(
providers: [
// Provider(create: (context) => HistoryProvider()),
Provider(create: (context) => MyWalletsProvider()),
ChangeNotifierProvider(create: (_) => HistoryProvider(''))
],
child: GraphQLProvider(
client: _client, client: _client,
child: HomeScreen(), child: HomeScreen(),
), ),

View File

@ -5,10 +5,13 @@ import 'package:sentry/sentry.dart' as sentry;
import 'package:qrscan/qrscan.dart' as scanner; import 'package:qrscan/qrscan.dart' as scanner;
class HistoryProvider with ChangeNotifier { class HistoryProvider with ChangeNotifier {
final TextEditingController _outputPubkey = new TextEditingController();
String pubkey = ''; String pubkey = '';
HistoryProvider(this.pubkey);
final TextEditingController _outputPubkey = new TextEditingController();
// String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug
ScrollController scrollController = new ScrollController(); // FetchMoreOptions opts;
// ScrollController scrollController = new ScrollController();
Future scan() async { Future scan() async {
await Permission.camera.request(); await Permission.camera.request();
@ -56,4 +59,13 @@ class HistoryProvider with ChangeNotifier {
return ''; return '';
} }
// scrollListener() {
// if (scrollController.offset >= scrollController.position.maxScrollExtent &&
// !scrollController.position.outOfRange) {
// print('On est en bas !!');
// // fetchMore(opts);
// notifyListeners();
// }
// }
} }

View File

@ -3,41 +3,35 @@ import 'package:gecko/query.dart';
import 'package:gecko/models/history.dart'; import 'package:gecko/models/history.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'dart:typed_data';
import 'dart:ui'; import 'dart:ui';
import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart';
import 'package:truncate/truncate.dart'; import 'package:truncate/truncate.dart';
//ignore: must_be_immutable //ignore: must_be_immutable
class HistoryScreen extends StatelessWidget with ChangeNotifier { class HistoryScreen extends StatelessWidget with ChangeNotifier {
Widget currentScreen;
Uint8List bytes = Uint8List(0);
final TextEditingController _outputPubkey = new TextEditingController(); final TextEditingController _outputPubkey = new TextEditingController();
ScrollController scrollController = new ScrollController();
final nRepositories = 20; final nRepositories = 20;
HistoryProvider _historyProvider;
// String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug FetchMore fetchMore;
String pubkey = ''; FetchMoreOptions opts;
bool isBuilding = true; // scrollListener() {
// if (scrollController.offset >= scrollController.position.maxScrollExtent &&
HistoryProvider historyProvider = HistoryProvider(); // !scrollController.position.outOfRange) {
// print('On est en bas !!');
scrollListener() { // print(opts.document);
if (historyProvider.scrollController.offset >= // fetchMore(opts);
historyProvider.scrollController.position.maxScrollExtent && // notifyListeners();
!historyProvider.scrollController.position.outOfRange) { // }
notifyListeners(); // }
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('Build pubkey : ' + pubkey); _historyProvider = Provider.of<HistoryProvider>(context);
print('Build this.pubkey : ' + this.pubkey); print('Build pubkey : ' + _historyProvider.pubkey);
print('isBuilding: ' + isBuilding.toString()); // scrollController.addListener(scrollListener);
historyProvider.scrollController.addListener(scrollListener);
historyProvider.scrollController = ScrollController();
return Scaffold( return Scaffold(
floatingActionButton: Container( floatingActionButton: Container(
height: 80.0, height: 80.0,
@ -46,11 +40,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
child: FloatingActionButton( child: FloatingActionButton(
heroTag: "buttonScan", heroTag: "buttonScan",
onPressed: () async { onPressed: () async {
await historyProvider.scan(); await _historyProvider.scan();
// print(resultScan);
// if (resultScan != 'false') {
// onTabTapped(0);
// }
}, },
child: Container( child: Container(
height: 40.0, height: 40.0,
@ -67,8 +57,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
// Entrée de la pubkey // Entrée de la pubkey
onChanged: (text) { onChanged: (text) {
print("Clé tappxé: $text"); print("Clé tappxé: $text");
this.pubkey = text; _historyProvider.isPubkey(text);
historyProvider.isPubkey(text);
}, },
controller: this._outputPubkey, controller: this._outputPubkey,
maxLines: 1, maxLines: 1,
@ -85,7 +74,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
disabledBorder: InputBorder.none, disabledBorder: InputBorder.none,
), ),
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)),
if (this.pubkey != '') historyQuery(), if (_historyProvider.pubkey != '') historyQuery(),
])); ]));
} }
@ -99,13 +88,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
options: QueryOptions( options: QueryOptions(
document: gql(getHistory), document: gql(getHistory),
variables: <String, dynamic>{ variables: <String, dynamic>{
'pubkey': this.pubkey, 'pubkey': _historyProvider.pubkey,
'number': nRepositories, 'number': nRepositories,
// set cursor to null so as to start at the beginning // set cursor to null so as to start at the beginning
'cursor': null 'cursor': null
}, },
), ),
builder: (QueryResult result, {refetch, FetchMore fetchMore}) { builder: (QueryResult result, {refetch, fetchMore}) {
if (result.isLoading && result.data == null) { if (result.isLoading && result.data == null) {
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
@ -138,7 +127,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
final num balance = final num balance =
removeDecimalZero(result.data['balance']['amount'] / 100); removeDecimalZero(result.data['balance']['amount'] / 100);
FetchMoreOptions opts = FetchMoreOptions( opts = FetchMoreOptions(
variables: {'cursor': fetchMoreCursor}, variables: {'cursor': fetchMoreCursor},
updateQuery: (previousResultData, fetchMoreResultData) { updateQuery: (previousResultData, fetchMoreResultData) {
final List<dynamic> repos = [ final List<dynamic> repos = [
@ -184,12 +173,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
List _transBC = parseHistory(blockchainTX); List _transBC = parseHistory(blockchainTX);
// Build history list // Build history list
return Expanded( return NotificationListener(
child: Expanded(
child: ListView( child: ListView(
controller: historyProvider.scrollController, controller: scrollController,
children: <Widget>[ children: <Widget>[
SizedBox(height: 7), SizedBox(height: 7),
if (this.pubkey != '') if (_historyProvider.pubkey != '')
Text(balance.toString() + ' Ğ1', Text(balance.toString() + ' Ğ1',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 30.0)), style: TextStyle(fontSize: 30.0)),
@ -197,8 +187,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
for (var repository in _transBC) for (var repository in _transBC)
ListTile( ListTile(
contentPadding: const EdgeInsets.all(5.0), contentPadding: const EdgeInsets.all(5.0),
leading: leading: Text(repository[3],
Text(repository[3], style: TextStyle(fontSize: 14.0)), style: TextStyle(fontSize: 14.0)),
title: Text( title: Text(
repository[1].toString() + repository[1].toString() +
'\n' + '\n' +
@ -206,11 +196,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
omission: "...", omission: "...",
position: TruncatePosition.end), position: TruncatePosition.end),
style: TextStyle(fontSize: 14.0)), style: TextStyle(fontSize: 14.0)),
subtitle: subtitle: Text(repository[5],
Text(repository[5], style: TextStyle(fontSize: 14.0)), style: TextStyle(fontSize: 14.0)),
dense: true, dense: true,
onTap: () { onTap: () {
historyProvider.isPubkey(repository[2]); this._outputPubkey.text = repository[2];
_historyProvider.isPubkey(repository[2]);
// notifyListeners();
}), }),
if (result.isLoading) if (result.isLoading)
Row( Row(
@ -220,7 +212,18 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
], ],
), ),
], ],
)); )),
onNotification: (t) {
// print(scrollController.position.pixels);
// print(scrollController.position.maxScrollExtent);
if (t is ScrollEndNotification &&
scrollController.position.pixels >=
scrollController.position.maxScrollExtent * 0.8) {
fetchMore(opts);
// notifyListeners();
}
return true;
});
}, },
), ),
], ],

View File

@ -5,7 +5,7 @@ description: A new Flutter project.
# pub.dev using `pub publish`. This is preferred for private packages. # pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.0+13 version: 0.0.0+14
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"