Improve padding

This commit is contained in:
poka 2021-01-09 10:48:06 +01:00
parent 855499e731
commit 70bd64bcef
3 changed files with 132 additions and 32 deletions

View File

@ -1,6 +1,11 @@
import 'dart:math';
import 'package:intl/intl.dart';
num removeDecimalZero(double n) {
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
return num.parse(result);
}
List parseHistory(txs) {
var transBC = [];
int i = 0;
@ -23,19 +28,20 @@ List parseHistory(txs) {
transBC[i].add(date);
print(
"DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}");
var amountBrut = int.parse(output.split(':')[0]);
int amountBrut = int.parse(output.split(':')[0]);
final base = int.parse(output.split(':')[1]);
final applyBase = base - currentBase;
final amount = amountBrut * pow(10, applyBase) / 100;
var amountUD = amount / currentUD;
final int applyBase = base - currentBase;
final num amount = removeDecimalZero(amountBrut * pow(10, applyBase) / 100);
num amountUD = amount / currentUD;
int padNbr = 14 - amount.toString().length;
if (direction == "RECEIVED") {
transBC[i].add(transaction['issuers'][0]);
transBC[i].add(amount);
transBC[i].add(' ' + amount.toString().padRight(padNbr));
transBC[i].add(amountUD.toStringAsFixed(2));
} else if (direction == "SENT") {
final outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transBC[i].add(outPubkey);
transBC[i].add(-amount);
transBC[i].add(' -' + amount.toString().padRight(padNbr - 1));
transBC[i].add(amountUD.toStringAsFixed(2));
}
transBC[i].add(transaction['comment']);

View File

@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:dubp/dubp.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:sentry/sentry.dart' as sentry;
import 'dart:io';
import 'dart:async';
@ -21,9 +22,15 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
TextEditingController _pubkey = new TextEditingController();
TextEditingController _pin = new TextEditingController();
String generatedMnemonic;
bool walletIsGenerated = false;
NewWallet actualWallet;
final formKey = GlobalKey<FormState>();
bool hasError = false;
String validPin = 'NO PIN';
String currentText = "";
var pinColor = Colors.grey[300];
@override
Widget build(BuildContext context) {
return SafeArea(
@ -95,23 +102,27 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
alignment: Alignment.bottomCenter,
child: new RaisedButton(
color: Color(0xffFFD68E),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return ValidStoreWalletScreen(
generatedMnemonic: this.generatedMnemonic,
generatedWallet:
this.actualWallet); //, this.actualWallet);
}),
).then((value) => setState(() {
if (value) {
_pin.clear();
_mnemonicController.clear();
_pubkey.clear();
}
}));
},
onPressed: walletIsGenerated
? () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return ValidStoreWalletScreen(
generatedMnemonic: this.generatedMnemonic,
generatedWallet: this.actualWallet);
}),
).then((value) => setState(() {
if (value) {
_pin.clear();
_mnemonicController.clear();
_pubkey.clear();
this.generatedMnemonic = null;
this.actualWallet = null;
this.walletIsGenerated = false;
}
}));
}
: null,
child: Text('Enregistrer ce wallet',
style: TextStyle(fontSize: 20))))),
SizedBox(height: 15)
@ -132,6 +143,7 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
}
}
this.actualWallet = await generateWallet(this.generatedMnemonic);
this.walletIsGenerated = true;
return this.generatedMnemonic;
}
@ -215,6 +227,75 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
color: Color(0xffFFD68E),
onPressed: () => storeWallet(widget.generatedWallet),
child: Text('Confirmer', style: TextStyle(fontSize: 20))),
// Form(
// child: Padding(
// padding:
// const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
// child: PinCodeTextField(
// appContext: context,
// pastedTextStyle: TextStyle(
// color: Colors.green.shade600,
// fontWeight: FontWeight.bold,
// ),
// length: 6,
// obscureText: false,
// obscuringCharacter: '*',
// animationType: AnimationType.fade,
// validator: (v) {
// if (v.length < 6) {
// return "Votre code PIN fait 6 caractères";
// } else {
// return null;
// }
// },
// pinTheme: PinTheme(
// shape: PinCodeFieldShape.box,
// borderRadius: BorderRadius.circular(5),
// fieldHeight: 60,
// fieldWidth: 50,
// activeFillColor: hasError ? Colors.orange : Colors.white,
// ),
// cursorColor: Colors.black,
// animationDuration: Duration(milliseconds: 300),
// textStyle: TextStyle(fontSize: 20, height: 1.6),
// backgroundColor: pinColor,
// enableActiveFill: false,
// errorAnimationController: errorController,
// controller: _enterPin,
// keyboardType: TextInputType.text,
// boxShadows: [
// BoxShadow(
// offset: Offset(0, 1),
// color: Colors.black12,
// blurRadius: 10,
// )
// ],
// onCompleted: (v) async {
// print("Completed");
// final resultWallet = await readLocalWallet(v.toUpperCase());
// if (resultWallet == 'bad') {
// errorController.add(ErrorAnimationType
// .shake); // Triggering error shake animation
// setState(() {
// hasError = true;
// pinColor = Colors.red[200];
// });
// } else {
// setState(() {
// pinColor = Colors.green[200];
// });
// }
// },
// onChanged: (value) {
// if (pinColor != Colors.grey[300]) {
// setState(() {
// pinColor = Colors.grey[300];
// });
// }
// print(value);
// },
// )),
// )
]),
),
);

View File

@ -77,7 +77,7 @@ class HistoryScreenState extends State<HistoryScreen> {
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: 'Tappez/Collez une clé publique, ou scannez',
hintStyle: TextStyle(fontSize: 15),
hintStyle: TextStyle(fontSize: 14),
contentPadding: EdgeInsets.symmetric(horizontal: 7, vertical: 15),
border: InputBorder.none,
focusedBorder: InputBorder.none,
@ -85,7 +85,7 @@ class HistoryScreenState extends State<HistoryScreen> {
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold)),
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)),
historyQuery(),
]);
}
@ -129,7 +129,8 @@ class HistoryScreenState extends State<HistoryScreen> {
final String fetchMoreCursor = pageInfo['endCursor'];
final num balance = result.data['balance']['amount'] / 100;
final num balance =
removeDecimalZero(result.data['balance']['amount'] / 100);
FetchMoreOptions opts = FetchMoreOptions(
variables: {'cursor': fetchMoreCursor},
@ -181,19 +182,26 @@ class HistoryScreenState extends State<HistoryScreen> {
child: ListView(
controller: _scrollController,
children: <Widget>[
SizedBox(height: 7),
if (this.pubkey != '')
Text(balance.toString() + ' Ğ1',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 30.0)),
SizedBox(height: 12),
for (var repository in _transBC)
ListTile(
contentPadding: const EdgeInsets.all(5.0),
leading: Text(repository[3].toString()),
title: Text(repository[1].toString() +
'\n' +
truncate(repository[2], 17,
omission: "...", position: TruncatePosition.end)),
subtitle: Text(repository[5]),
leading:
Text(repository[3], style: TextStyle(fontSize: 14.0)),
title: Text(
repository[1].toString() +
'\n' +
truncate(repository[2], 17,
omission: "...",
position: TruncatePosition.end),
style: TextStyle(fontSize: 14.0)),
subtitle:
Text(repository[5], style: TextStyle(fontSize: 14.0)),
dense: true,
onTap: () {
isPubkey(repository[2]);
@ -264,4 +272,9 @@ class HistoryScreenState extends State<HistoryScreen> {
return '';
}
num removeDecimalZero(double n) {
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
return num.parse(result);
}
}