Skip to content

Commit f93c7eb

Browse files
committed
fix bugs & new function
1 parent 12e1984 commit f93c7eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+425
-342
lines changed
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
package com.xdag.io
22

3-
import io.flutter.embedding.android.FlutterActivity
3+
import android.os.Build
4+
import android.os.Bundle
5+
import androidx.activity.OnBackPressedCallback
46
import io.flutter.embedding.android.FlutterFragmentActivity
7+
import io.flutter.embedding.engine.FlutterEngine
8+
import io.flutter.plugins.GeneratedPluginRegistrant
9+
510
class MainActivity: FlutterFragmentActivity() {
11+
private lateinit var onBackPressedCallback: OnBackPressedCallback
12+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
13+
GeneratedPluginRegistrant.registerWith(flutterEngine)
14+
}
15+
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
// android 33
19+
if (Build.VERSION.SDK_INT >= 33) {
20+
onBackPressedCallback = object : OnBackPressedCallback(true) {
21+
override fun handleOnBackPressed() {
22+
// flutter 侧处理返回事件
23+
flutterEngine!!.navigationChannel.popRoute()
24+
}
25+
}
26+
// 注册 OnBackPressedCallback
27+
val onBackPressedDispatcher = onBackPressedDispatcher
28+
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
29+
}
30+
}
31+
32+
override fun onDestroy() {
33+
super.onDestroy()
34+
if (Build.VERSION.SDK_INT >= 33) {
35+
onBackPressedCallback.remove()
36+
}
37+
}
38+
39+
override fun onBackPressed() {
40+
// super.onBackPressed()
41+
if (Build.VERSION.SDK_INT < 33) {
42+
flutterEngine!!.navigationChannel.popRoute();
43+
}
44+
}
45+
46+
647
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="100dp"
3+
android:height="100dp"
4+
android:viewportWidth="1024"
5+
android:viewportHeight="1024">
6+
<path
7+
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"
8+
android:fillColor="#A7B6C4"/>
9+
<path
10+
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"
11+
android:fillColor="#A7B6C4"/>
12+
<path
13+
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"
14+
android:fillColor="#A7B6C4"/>
15+
</vector>

lib/common/global.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class Global {
6868
];
6969
if (contactsList != null) {
7070
for (var item in contactsList) {
71-
contactsListBox.add(ContactsItem.fromJson(item));
71+
ContactsItem ele = ContactsItem.fromJson(item);
72+
if (ele.address != '4duPWMbYUgAifVYkKDCWxLvRRkSByf5gb') {
73+
contactsListBox.add(ele);
74+
}
7275
}
7376
}
7477
PackageInfo packageInfo = await PackageInfo.fromPlatform();

lib/common/helper.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import 'dart:io';
2+
import 'package:chinese_font_library/chinese_font_library.dart';
23
import 'package:flutter/cupertino.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter_statusbarcolor_ns/flutter_statusbarcolor_ns.dart';
56
import 'package:hex/hex.dart';
67
import 'package:pointycastle/export.dart';
8+
import 'package:provider/provider.dart';
79
import 'package:xdag/common/color.dart';
10+
import 'package:xdag/model/config_modal.dart';
811
import 'package:xdag/widget/button.dart';
912
import 'dart:typed_data';
1013
import 'package:bip32/bip32.dart' as bip32;
@@ -13,12 +16,9 @@ import 'package:fast_base58/fast_base58.dart';
1316
import 'package:xdag/widget/desktop.dart';
1417

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

@@ -71,6 +71,14 @@ class Helper {
7171
return result;
7272
}
7373

74+
static TextStyle fitChineseFont(BuildContext context, TextStyle textStyle, {listen = true}) {
75+
ConfigModal configModal = Provider.of<ConfigModal>(context, listen: listen);
76+
if (configModal.local == const Locale("ja") || configModal.local == const Locale("zh")) {
77+
return textStyle.useSystemChineseFont();
78+
}
79+
return textStyle;
80+
}
81+
7482
// show toast
7583
static void showToast(BuildContext context, String msg) {
7684
ScaffoldMessenger.of(context).removeCurrentSnackBar();
@@ -80,18 +88,11 @@ class Helper {
8088
duration: const Duration(seconds: 1),
8189
content: Text(
8290
msg,
83-
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
84-
),
85-
));
86-
}
87-
88-
static void showSnackBar(String msg) {
89-
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
90-
backgroundColor: DarkColors.mainColor,
91-
behavior: SnackBarBehavior.floating,
92-
content: Text(
93-
msg,
94-
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
91+
style: Helper.fitChineseFont(
92+
context,
93+
const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Colors.white),
94+
listen: false,
95+
),
9596
),
9697
));
9798
}
@@ -127,7 +128,7 @@ class Helper {
127128
child: Center(
128129
child: Text(
129130
title,
130-
style: const TextStyle(color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w700),
131+
style: Helper.fitChineseFont(context, const TextStyle(color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w700)),
131132
),
132133
)),
133134
const SizedBox(width: 40)

lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class MyWidget extends StatelessWidget {
8484
supportedLocales: AppLocalizations.supportedLocales,
8585
locale: configModal.local,
8686
theme: ThemeData(
87-
// 日文,中文使用系统默认字体
8887
fontFamily: configModal.local == const Locale("ja") || configModal.local == const Locale("zh") ? "system-font" : "RobotoMono",
8988
scrollbarTheme: !Helper.isDesktop
9089
? null

lib/model/contacts_modal.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class ContactsModal extends ChangeNotifier {
2222
updateList() async {
2323
List<String> list = [];
2424
for (var i in Global.contactsListBox) {
25-
list.add(i.toJsonString());
25+
if (i.address != '4duPWMbYUgAifVYkKDCWxLvRRkSByf5gb') {
26+
list.add(i.toJsonString());
27+
}
2628
}
2729
await Global.prefs.setStringList(Global.contactsListKey, list);
2830
notifyListeners();
@@ -32,7 +34,7 @@ class ContactsModal extends ChangeNotifier {
3234
try {
3335
ContactsItem item = ContactsItem(name, address);
3436
// 插入到第一个
35-
Global.contactsListBox.insert(0, item);
37+
Global.contactsListBox.insert(1, item);
3638
updateList();
3739
} catch (e) {
3840
rethrow;

lib/page/common/add_contacts_page.dart

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class _AddContactsPage extends State<AddContactsPage> {
125125
child: Column(
126126
crossAxisAlignment: CrossAxisAlignment.start,
127127
children: [
128-
Text(AppLocalizations.of(context).contact_name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
128+
Text(AppLocalizations.of(context).contact_name, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
129129
const SizedBox(height: 13),
130130
AutoSizeTextField(
131131
controller: controller2,
@@ -147,18 +147,13 @@ class _AddContactsPage extends State<AddContactsPage> {
147147
},
148148
textInputAction: TextInputAction.next,
149149
keyboardAppearance: Brightness.dark,
150-
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white),
150+
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
151151
decoration: InputDecoration(
152152
filled: true,
153153
contentPadding: const EdgeInsets.all(15),
154154
fillColor: DarkColors.blockColor,
155155
hintText: AppLocalizations.of(context).contact_name,
156-
hintStyle: const TextStyle(
157-
decoration: TextDecoration.none,
158-
fontSize: 16,
159-
fontWeight: FontWeight.w500,
160-
color: Colors.white54,
161-
),
156+
hintStyle: Helper.fitChineseFont(context, const TextStyle(decoration: TextDecoration.none, fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white54)),
162157
enabledBorder: const OutlineInputBorder(
163158
borderSide: BorderSide.none,
164159
borderRadius: BorderRadius.all(Radius.circular(10)),
@@ -170,7 +165,7 @@ class _AddContactsPage extends State<AddContactsPage> {
170165
),
171166
),
172167
const SizedBox(height: 25),
173-
Text(AppLocalizations.of(context).walletAddress, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
168+
Text(AppLocalizations.of(context).walletAddress, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
174169
const SizedBox(height: 13),
175170
AutoSizeTextField(
176171
controller: controller,
@@ -192,22 +187,13 @@ class _AddContactsPage extends State<AddContactsPage> {
192187
},
193188
textInputAction: TextInputAction.next,
194189
keyboardAppearance: Brightness.dark,
195-
style: const TextStyle(
196-
fontSize: 16,
197-
fontWeight: FontWeight.w500,
198-
color: Colors.white,
199-
),
190+
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
200191
decoration: InputDecoration(
201192
filled: true,
202193
contentPadding: const EdgeInsets.all(15),
203194
fillColor: DarkColors.blockColor,
204195
hintText: AppLocalizations.of(context).walletAddress,
205-
hintStyle: const TextStyle(
206-
decoration: TextDecoration.none,
207-
fontSize: 16,
208-
fontWeight: FontWeight.w500,
209-
color: Colors.white54,
210-
),
196+
hintStyle: Helper.fitChineseFont(context, const TextStyle(decoration: TextDecoration.none, fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white54)),
211197
enabledBorder: const OutlineInputBorder(
212198
borderSide: BorderSide.none,
213199
borderRadius: BorderRadius.all(Radius.circular(10)),
@@ -227,7 +213,7 @@ class _AddContactsPage extends State<AddContactsPage> {
227213
color: DarkColors.redColorMask,
228214
borderRadius: BorderRadius.circular(10),
229215
),
230-
child: Text(error, style: const TextStyle(fontSize: 12, color: DarkColors.redColor, fontWeight: FontWeight.w500)),
216+
child: Text(error, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 12, color: DarkColors.redColor, fontWeight: FontWeight.w500))),
231217
)
232218
else
233219
const SizedBox(height: 20),

lib/page/common/back_up_page.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class BackUpPage extends StatelessWidget {
5656
padding: const EdgeInsets.fromLTRB(15, 30, 15, 0),
5757
child: Column(
5858
children: [
59-
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)),
59+
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))),
6060
const SizedBox(height: 15),
6161
Text(
6262
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),
63-
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
63+
style: Helper.fitChineseFont(context, const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
6464
),
6565
const SizedBox(height: 20),
6666
Container(
@@ -72,7 +72,7 @@ class BackUpPage extends StatelessWidget {
7272
),
7373
// 每两个元素一行
7474
child: args.type == 1
75-
? Text(args.data, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))
75+
? Text(args.data, style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)))
7676
: Wrap(
7777
spacing: 20,
7878
runSpacing: 20,
@@ -85,7 +85,7 @@ class BackUpPage extends StatelessWidget {
8585
borderRadius: BorderRadius.circular(25),
8686
),
8787
child: Center(
88-
child: Text('${e.index}. ${e.value}', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
88+
child: Text('${e.index}. ${e.value}', style: Helper.fitChineseFont(context, const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white))),
8989
)))
9090
.toList(),
9191
),

0 commit comments

Comments
 (0)