import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; // import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:qrscan/qrscan.dart' as scanner; import 'package:intl/intl.dart'; // import 'package:flutter_html_view'; import 'api.dart'; import "package:dio/dio.dart"; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { Uint8List bytes = Uint8List(0); TextEditingController _outputPubkey; TextEditingController _outputBalance; TextEditingController _outputHistory; @override initState() { super.initState(); this._outputPubkey = new TextEditingController(); this._outputBalance = new TextEditingController(); this._outputHistory = new TextEditingController(); // checkNode().then((result) { // setState(() { // _result = result; // }); // }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: Colors.grey[300], body: Builder( builder: (BuildContext context) { return ListView( children: [ Container( color: Colors.white, child: Column( children: [ SizedBox(height: 20), TextField( enabled: false, controller: this._outputPubkey, maxLines: 1, textAlign: TextAlign.center, decoration: InputDecoration( hintText: 'Clé publique scanné', hintStyle: TextStyle(fontSize: 15), contentPadding: EdgeInsets.symmetric( horizontal: 7, vertical: 15), ), style: TextStyle( fontSize: 15.0, color: Colors.black, fontWeight: FontWeight.bold)), TextField( enabled: false, controller: this._outputBalance, maxLines: 1, textAlign: TextAlign.center, decoration: InputDecoration( hintText: 'Solde du compte scanné', hintStyle: TextStyle(fontSize: 15), contentPadding: EdgeInsets.symmetric( horizontal: 7, vertical: 15), ), style: TextStyle(fontSize: 30.0, color: Colors.black)), TextField( enabled: false, controller: this._outputHistory, maxLines: null, keyboardType: TextInputType.multiline, decoration: InputDecoration( prefixIcon: Icon(Icons.wrap_text), hintText: 'Historique du compte scanné', hintStyle: TextStyle(fontSize: 15), contentPadding: EdgeInsets.symmetric( horizontal: 7, vertical: 15), ), style: TextStyle( fontSize: 13.0, height: 1.5, color: Colors.black)), SizedBox(height: 20), this._buttonGroup(), SizedBox(height: 70), // Expanded( // child: ListView.builder( // padding: const EdgeInsets.all(8), // itemCount: names.length, // itemBuilder: (BuildContext context, int index) { // return Container( // height: 50, // margin: EdgeInsets.all(2), // child: Center( // child: Text( // '${names[index]} (${msgCount[index]})', // style: TextStyle(fontSize: 18), // )), // ); // })) ], ), ), ], ); }, ) // floatingActionButton: FloatingActionButton( // onPressed: () => _scanBytes(), // tooltip: 'Prennez une photo', // child: const Icon(Icons.camera_alt), // ), ), ); } Widget _buttonGroup() { return Row( children: [ Expanded( flex: 1, child: SizedBox( height: 120, child: InkWell( onTap: _scan, child: Card( child: Column( children: [ Expanded( flex: 2, child: Image.asset('images/scanner.png'), ), Divider(height: 20), Expanded(flex: 1, child: Text("Scanner")), ], ), ), ), ), ), ], ); } Future checkNode() async { final response = await Dio().post(graphqlEndpoint); return response; } Future _scan() async { await Permission.camera.request(); String barcode = await scanner.scan(); if (barcode == null) { print('nothing return.'); } else { this._outputPubkey.text = ""; this._outputBalance.text = ""; this._outputHistory.text = ""; // final udValue = await getUD(); this._outputPubkey.text = barcode; final myBalance = await getBalance(barcode.toString()); this._outputBalance.text = myBalance.toString() + " Ğ1"; final myHistory = await getHistory(barcode.toString()); if (myHistory == false) { return false; } String historyBC = ""; var j = 0; for (var i in myHistory[0]) { var dateBrut = i[0]; dateBrut = DateTime.fromMillisecondsSinceEpoch(dateBrut * 1000); final DateFormat formatter = DateFormat('dd-MM-yy - H:M'); final String date = formatter.format(dateBrut); final issuer = i[1]; final amount = i[2]; // final amountUD = i[3]; final comment = i[4]; historyBC += date.toString() + " \n " + issuer.toString() + " \n " + amount.toString() + " Ğ1\n " + comment.toString() + "\n---\n"; j++; if (j >= 10) { break; } } String historyMP = ""; j = 0; for (var i in myHistory[1]) { if (i == null) { break; } var dateBrut = "Now"; final issuer = i[1]; final amount = i[2]; // final amountUD = i[3]; final comment = i[4]; historyMP += "EN COURS DE RECEPTION\n" + dateBrut.toString() + " \n " + issuer.toString() + " \n " + amount.toString() + " Ğ1\n " + comment.toString() + "\n---\n"; } var history; // print(historyMP.toString()); if (historyMP == "") { history = historyBC; } else { history = historyMP + '\n' + historyBC; } this._outputHistory.text = history; } } // Future _generateBarCode(String inputCode) async { // if (inputCode != null && inputCode.isNotEmpty) { // // print("Résultat du scan: " + inputCode); // Uint8List result = await scanner.generateBarCode(inputCode); // this.setState(() => this.bytes = result); // } else { // print("Veuillez renseigner une clé publique"); // } // } }