Skip to content

Commit

Permalink
Supports custom QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingCoding committed May 7, 2023
1 parent b92e98b commit f9505a0
Show file tree
Hide file tree
Showing 27 changed files with 612 additions and 93 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
Expand Down
10 changes: 9 additions & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
</manifest>
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<application
android:requestLegacyExternalStorage="true"
android:enableOnBackInvokedCallback="true"
android:label="XDAG-Pro"
android:name="${applicationName}"
Expand Down
1 change: 0 additions & 1 deletion android/app/src/main/kotlin/com/xdag/io/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class MainActivity: FlutterFragmentActivity() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
}

override fun onDestroy() {
super.onDestroy()
if (Build.VERSION.SDK_INT >= 33) {
Expand Down
1 change: 1 addition & 0 deletions android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
Expand Down
4 changes: 2 additions & 2 deletions lib/common/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class Helper {
}

// show toast
static void showToast(BuildContext context, String msg) {
static void showToast(BuildContext context, String msg, {Color color = DarkColors.mainColor}) {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: DarkColors.mainColor,
backgroundColor: color,
behavior: SnackBarBehavior.floating,
duration: const Duration(seconds: 1),
content: Text(
Expand Down
9 changes: 9 additions & 0 deletions lib/common/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ class TransactionHelper {
};
}

static bool isJson(String str) {
try {
json.decode(str);
} catch (e) {
return false;
}
return true;
}

static bool checkAddress(String address) {
try {
if (address.isEmpty) return false;
Expand Down
6 changes: 5 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"Gesendet",
"received":"Empfangen",
"qr_code":"QR-code",
"save_to_album":"In Album speichern"
"save_image":"Bild speichern",
"payment":"Zahlung",
"contact":"Kontakt",
"customize_QR_code":"QR-code anpassen",
"name":"Name"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"Sent",
"received":"Received",
"qr_code":"QR Code",
"save_to_album":"Save to album"
"save_image":"Save Image",
"payment":"Payment",
"contact":"Contact",
"customize_QR_code":"Customize QR Code",
"name":"Name"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent": "Enviado",
"received": "Recibido",
"qr_code": "Código QR",
"save_to_album": "Guardar en el álbum"
"save_image":"Guardar imagen",
"payment":"Pago",
"contact":"Contacto",
"customize_QR_code":"Personalizar código QR",
"name":"Nombre"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent": "Envoyé",
"received": "Reçu",
"qr_code": "Code QR",
"save_to_album": "Enregistrer dans l'album"
"save_image":"Enregistrer l'image",
"payment":"Paiement",
"contact":"Contact",
"customize_QR_code":"Personnaliser le code QR",
"name":"Nom"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"Inviato",
"received":"Ricevuto",
"qr_code":"Codice QR",
"save_to_album":"Salva in album"
"save_image":"Salva immagine",
"payment":"Pagamento",
"contact":"Contatto",
"customize_QR_code":"Personalizza codice QR",
"name":"Nome"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"送信",
"received":"受け取る",
"qr_code":"QRコード",
"save_to_album":"アルバムに保存"
"save_image":"画像を保存",
"payment":"支払い",
"contact":"連絡先",
"customize_QR_code":"カスタマイズQRコード",
"name":"名前"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"Отправлено",
"received":"Получено",
"qr_code":"QR-код",
"save_to_album":"Сохранить в альбом"
"save_image":"Сохранить изображение",
"payment":"Оплата",
"contact":"Контакт",
"customize_QR_code":"Настроить QR-код",
"name":"Имя"
}
6 changes: 5 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"sent":"发送",
"received":"接收",
"qr_code":"二维码",
"save_to_album":"保存到相册"
"save_image":"保存图片",
"payment":"付款",
"contact":"联系人",
"customize_QR_code":"自定义二维码",
"name":"名称"
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MyWidget extends StatelessWidget {
"/webview": (context) => const WebViewPage(),
"/back_up_test_start": (context) => const BackUpStartPage(),
"/back_up_test": (context) => const BackUpTestPage(),
"/customize_qr": (context) => const CustomizeQrPage(),
},
),
));
Expand Down
1 change: 1 addition & 0 deletions lib/model/wallet_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class WalletModal extends ChangeNotifier {

deleteWallet(Wallet wallet, int index) async {
bool isDef = wallet.isDef;
await Global.prefs.remove('${wallet.address}_qr');
await Global.deleteWallet(wallet.address);
// await wallet.delete();
await walletList.deleteAt(index);
Expand Down
19 changes: 16 additions & 3 deletions lib/page/common/add_contacts_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:auto_size_text_field/auto_size_text_field.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -82,13 +83,25 @@ class _AddContactsPage extends State<AddContactsPage> {
errQrText: AppLocalizations.of(context).qr_not_found,
);
if (res != null) {
bool flag = TransactionHelper.checkAddress(res);
// 判断 res 是否是一个 json 字符串
bool isJosn = TransactionHelper.isJson(res);
Map<String, dynamic> json = {};
String address = "";
if (isJosn) {
json = const JsonDecoder().convert(res);
address = json["address"] ?? "";
}
bool flag = TransactionHelper.checkAddress(address);
if (flag) {
setState(() {
error = "";
});
controller.text = res;
controller.selection = TextSelection.fromPosition(TextPosition(offset: res.length));
controller.text = address;
controller.selection = TextSelection.fromPosition(TextPosition(offset: address.length));
if (json["name"] != null) {
controller2.text = json["name"];
controller2.selection = TextSelection.fromPosition(TextPosition(offset: json["name"].length));
}
} else {
controller.clear();
controller.selection = TextSelection.fromPosition(const TextPosition(offset: 0));
Expand Down
27 changes: 24 additions & 3 deletions lib/page/detail/contacts_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:auto_size_text_field/auto_size_text_field.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -77,15 +78,35 @@ class ContactsStatePage extends State<ContactsPage> {
errQrText: AppLocalizations.of(context).qr_not_found,
);
if (res != null) {
bool flag = TransactionHelper.checkAddress(res);
// 判断 res 是否是一个 json 字符串
bool isJosn = TransactionHelper.isJson(res);
Map<String, dynamic> json = {};
String address = "";
if (isJosn) {
json = const JsonDecoder().convert(res);
address = json["address"] ?? "";
}
bool flag = TransactionHelper.checkAddress(address);
if (flag) {
setState(() {
// walletAddress = res;
isButtonEnable = true;
error = "";
});
controller.text = res;
controller.selection = TextSelection.fromPosition(TextPosition(offset: res.length));
controller.text = address;
controller.selection = TextSelection.fromPosition(TextPosition(offset: address.length));
if (mounted) {
Navigator.pushNamed(
context,
'/send',
arguments: SendPageRouteParams(
address: controller.text,
amount: json["amount"] ?? "",
remark: json["remark"] ?? "",
name: json["name"] ?? "",
),
);
}
} else {
controller.clear();
controller.selection = TextSelection.fromPosition(const TextPosition(offset: 0));
Expand Down
Loading

0 comments on commit f9505a0

Please sign in to comment.