Skip to content

Commit

Permalink
fix bugs & new function
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingCoding committed Apr 22, 2023
1 parent 12e1984 commit f93c7eb
Show file tree
Hide file tree
Showing 42 changed files with 425 additions and 342 deletions.
43 changes: 42 additions & 1 deletion android/app/src/main/kotlin/com/xdag/io/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
package com.xdag.io

import io.flutter.embedding.android.FlutterActivity
import android.os.Build
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
private lateinit var onBackPressedCallback: OnBackPressedCallback
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// android 33
if (Build.VERSION.SDK_INT >= 33) {
onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// flutter 侧处理返回事件
flutterEngine!!.navigationChannel.popRoute()
}
}
// 注册 OnBackPressedCallback
val onBackPressedDispatcher = onBackPressedDispatcher
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
}

override fun onDestroy() {
super.onDestroy()
if (Build.VERSION.SDK_INT >= 33) {
onBackPressedCallback.remove()
}
}

override fun onBackPressed() {
// super.onBackPressed()
if (Build.VERSION.SDK_INT < 33) {
flutterEngine!!.navigationChannel.popRoute();
}
}


}
15 changes: 15 additions & 0 deletions android/app/src/main/res/drawable/change.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M951.9,1023.4a25.6,25.6 0,0 1,-18.1 -7.5L8.5,90.7a25.6,25.6 0,0 1,36.2 -36.2l925.3,925.3a25.6,25.6 0,0 1,-18.1 43.6zM212.5,152.5A466.8,466.8 0,0 1,511.6 44.2a468.2,468.2 0,0 1,360.1 767.5l30.3,30.3A510.9,510.9 0,0 0,182 122z"
android:fillColor="#A7B6C4"/>
<path
android:pathData="M810.2,873.2A468.3,468.3 0,0 1,43.4 512.5a466.7,466.7 0,0 1,107.5 -298.4l-30.4,-30.4a510.9,510.9 0,0 0,720.1 719.9zM375.5,315.5h54.1l50.4,104.4 32.2,32.1c2.3,-5.1 4.8,-10.2 7.4,-15.4L579.3,315.4h90l-92.1,176.8h69v71.9h-21.8l173.1,173.1c112.6,-142.5 102.1,-352.6 -29.2,-481.7a362,362 0,0 0,-481 -28.3z"
android:fillColor="#A7B6C4"/>
<path
android:pathData="M600.7,663.7h-53.2v76.8H468.6v-76.8H370.7v-70.8h97.9v-28.9H370.7v-71.6h58.6L225.6,288.6C113.6,430.7 123.9,640.1 254.4,769.3a363.3,363.3 0,0 0,481 29.1z"
android:fillColor="#A7B6C4"/>
</vector>
5 changes: 4 additions & 1 deletion lib/common/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class Global {
];
if (contactsList != null) {
for (var item in contactsList) {
contactsListBox.add(ContactsItem.fromJson(item));
ContactsItem ele = ContactsItem.fromJson(item);
if (ele.address != '4duPWMbYUgAifVYkKDCWxLvRRkSByf5gb') {
contactsListBox.add(ele);
}
}
}
PackageInfo packageInfo = await PackageInfo.fromPlatform();
Expand Down
33 changes: 17 additions & 16 deletions lib/common/helper.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:io';
import 'package:chinese_font_library/chinese_font_library.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_statusbarcolor_ns/flutter_statusbarcolor_ns.dart';
import 'package:hex/hex.dart';
import 'package:pointycastle/export.dart';
import 'package:provider/provider.dart';
import 'package:xdag/common/color.dart';
import 'package:xdag/model/config_modal.dart';
import 'package:xdag/widget/button.dart';
import 'dart:typed_data';
import 'package:bip32/bip32.dart' as bip32;
Expand All @@ -13,12 +16,9 @@ import 'package:fast_base58/fast_base58.dart';
import 'package:xdag/widget/desktop.dart';

class Helper {
static final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
static bool isDesktop = Platform.isLinux || Platform.isMacOS || Platform.isWindows;
static bool checkName(String name) {
// RegExp regExp = RegExp(r"^[a-zA-Z0-9\u4e00-\u9fa5]+$");
RegExp regExp2 = RegExp(r",");
// print(regExp2.hasMatch(name));
return !regExp2.hasMatch(name);
}

Expand Down Expand Up @@ -71,6 +71,14 @@ class Helper {
return result;
}

static TextStyle fitChineseFont(BuildContext context, TextStyle textStyle, {listen = true}) {
ConfigModal configModal = Provider.of<ConfigModal>(context, listen: listen);
if (configModal.local == const Locale("ja") || configModal.local == const Locale("zh")) {
return textStyle.useSystemChineseFont();
}
return textStyle;
}

// show toast
static void showToast(BuildContext context, String msg) {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
Expand All @@ -80,18 +88,11 @@ class Helper {
duration: const Duration(seconds: 1),
content: Text(
msg,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
),
));
}

static void showSnackBar(String msg) {
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
backgroundColor: DarkColors.mainColor,
behavior: SnackBarBehavior.floating,
content: Text(
msg,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
style: Helper.fitChineseFont(
context,
const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
listen: false,
),
),
));
}
Expand Down Expand Up @@ -127,7 +128,7 @@ class Helper {
child: Center(
child: Text(
title,
style: const TextStyle(color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w700),
style: Helper.fitChineseFont(context, const TextStyle(color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w700)),
),
)),
const SizedBox(width: 40)
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class MyWidget extends StatelessWidget {
supportedLocales: AppLocalizations.supportedLocales,
locale: configModal.local,
theme: ThemeData(
// 日文,中文使用系统默认字体
fontFamily: configModal.local == const Locale("ja") || configModal.local == const Locale("zh") ? "system-font" : "RobotoMono",
scrollbarTheme: !Helper.isDesktop
? null
Expand Down
6 changes: 4 additions & 2 deletions lib/model/contacts_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ContactsModal extends ChangeNotifier {
updateList() async {
List<String> list = [];
for (var i in Global.contactsListBox) {
list.add(i.toJsonString());
if (i.address != '4duPWMbYUgAifVYkKDCWxLvRRkSByf5gb') {
list.add(i.toJsonString());
}
}
await Global.prefs.setStringList(Global.contactsListKey, list);
notifyListeners();
Expand All @@ -32,7 +34,7 @@ class ContactsModal extends ChangeNotifier {
try {
ContactsItem item = ContactsItem(name, address);
// 插入到第一个
Global.contactsListBox.insert(0, item);
Global.contactsListBox.insert(1, item);
updateList();
} catch (e) {
rethrow;
Expand Down
28 changes: 7 additions & 21 deletions lib/page/common/add_contacts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class _AddContactsPage extends State<AddContactsPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(AppLocalizations.of(context).contact_name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
Text(AppLocalizations.of(context).contact_name, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
const SizedBox(height: 13),
AutoSizeTextField(
controller: controller2,
Expand All @@ -147,18 +147,13 @@ class _AddContactsPage extends State<AddContactsPage> {
},
textInputAction: TextInputAction.next,
keyboardAppearance: Brightness.dark,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white),
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
decoration: InputDecoration(
filled: true,
contentPadding: const EdgeInsets.all(15),
fillColor: DarkColors.blockColor,
hintText: AppLocalizations.of(context).contact_name,
hintStyle: const TextStyle(
decoration: TextDecoration.none,
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white54,
),
hintStyle: Helper.fitChineseFont(context, const TextStyle(decoration: TextDecoration.none, fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white54)),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(10)),
Expand All @@ -170,7 +165,7 @@ class _AddContactsPage extends State<AddContactsPage> {
),
),
const SizedBox(height: 25),
Text(AppLocalizations.of(context).walletAddress, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
Text(AppLocalizations.of(context).walletAddress, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
const SizedBox(height: 13),
AutoSizeTextField(
controller: controller,
Expand All @@ -192,22 +187,13 @@ class _AddContactsPage extends State<AddContactsPage> {
},
textInputAction: TextInputAction.next,
keyboardAppearance: Brightness.dark,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white,
),
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
decoration: InputDecoration(
filled: true,
contentPadding: const EdgeInsets.all(15),
fillColor: DarkColors.blockColor,
hintText: AppLocalizations.of(context).walletAddress,
hintStyle: const TextStyle(
decoration: TextDecoration.none,
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white54,
),
hintStyle: Helper.fitChineseFont(context, const TextStyle(decoration: TextDecoration.none, fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white54)),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(10)),
Expand All @@ -227,7 +213,7 @@ class _AddContactsPage extends State<AddContactsPage> {
color: DarkColors.redColorMask,
borderRadius: BorderRadius.circular(10),
),
child: Text(error, style: const TextStyle(fontSize: 12, color: DarkColors.redColor, fontWeight: FontWeight.w500)),
child: Text(error, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 12, color: DarkColors.redColor, fontWeight: FontWeight.w500))),
)
else
const SizedBox(height: 20),
Expand Down
8 changes: 4 additions & 4 deletions lib/page/common/back_up_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class BackUpPage extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(15, 30, 15, 0),
child: Column(
children: [
Text(args.type == 0 ? AppLocalizations.of(context).write_Down_Mnemonics : AppLocalizations.of(context).write_Down_PrivateKey, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: DarkColors.mainColor)),
Text(args.type == 0 ? AppLocalizations.of(context).write_Down_Mnemonics : AppLocalizations.of(context).write_Down_PrivateKey, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: DarkColors.mainColor))),
const SizedBox(height: 15),
Text(
args.isBackup ? AppLocalizations.of(context).backup_test_tips_3 : (args.type == 0 ? AppLocalizations.of(context).write_Down_Mnemonics_tips : AppLocalizations.of(context).write_Down_PrivateKey_tips),
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
),
const SizedBox(height: 20),
Container(
Expand All @@ -72,7 +72,7 @@ class BackUpPage extends StatelessWidget {
),
// 每两个元素一行
child: args.type == 1
? Text(args.data, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))
? Text(args.data, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)))
: Wrap(
spacing: 20,
runSpacing: 20,
Expand All @@ -85,7 +85,7 @@ class BackUpPage extends StatelessWidget {
borderRadius: BorderRadius.circular(25),
),
child: Center(
child: Text('${e.index}. ${e.value}', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
child: Text('${e.index}. ${e.value}', style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
)))
.toList(),
),
Expand Down
Loading

0 comments on commit f93c7eb

Please sign in to comment.