助记词转换
This commit is contained in:
172
lib/views/auth/create/index_page.dart
Normal file
172
lib/views/auth/create/index_page.dart
Normal file
@@ -0,0 +1,172 @@
|
||||
import 'package:bip39_multi_language/bip39.dart' as bip39;
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/routes/auth_routes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AuthCreatePage extends StatefulWidget {
|
||||
const AuthCreatePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AuthCreatePage> createState() => _AuthCreatePageState();
|
||||
}
|
||||
|
||||
class _AuthCreatePageState extends State<AuthCreatePage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final TabController _tabController;
|
||||
|
||||
List<String> _englishMnemonic = [];
|
||||
List<String> _chineseMnemonic = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(
|
||||
length: 2,
|
||||
vsync: this,
|
||||
);
|
||||
_generateMnemonic();
|
||||
}
|
||||
|
||||
void _generateMnemonic() {
|
||||
String _englishBip39Str = bip39.generateMnemonic(language: 'english');
|
||||
String _chineseBip39Str = bip39.generateMnemonic(language: 'chinese');
|
||||
|
||||
setState(() {
|
||||
_englishMnemonic = _englishBip39Str.split(' ');
|
||||
_chineseMnemonic = _chineseBip39Str.split(' ');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('备份助记词'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('跳过备份'),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: true,
|
||||
indicatorColor: AppColors.primary,
|
||||
indicatorWeight: 5,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
tabs: const [
|
||||
Tab(
|
||||
text: 'English',
|
||||
),
|
||||
Tab(
|
||||
text: '中文',
|
||||
),
|
||||
],
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 8.0),
|
||||
child: Text(
|
||||
'请务必抄下助记词,确定之后将进行校验',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_moArea(_englishMnemonic),
|
||||
_moArea(_chineseMnemonic),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: Get.height * 0.382,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: const Text(
|
||||
'提示:请勿截图!如果有人获取您的助记词将直接获取您的资产,请抄写助记词并存放在安全的地方,我们会在下一屏幕进行校验,',
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_generateMnemonic();
|
||||
},
|
||||
child: const Text('更换助记词'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
var language = _tabController.index;
|
||||
Get.toNamed(
|
||||
AuthRoutes.createVerify,
|
||||
arguments: {
|
||||
'language': language == 0 ? 'english' : 'chinese',
|
||||
'mnemonic':
|
||||
language == 0 ? _englishMnemonic : _chineseMnemonic
|
||||
},
|
||||
);
|
||||
},
|
||||
child: const Text('开始备份'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _moArea(List<String> mnemonic) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 4.5 / 1,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
),
|
||||
itemCount: mnemonic.length,
|
||||
itemBuilder: (_, i) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: AppColors.border,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'${i + 1}. ${mnemonic[i]}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
65
lib/views/auth/create/verify_page.dart
Normal file
65
lib/views/auth/create/verify_page.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AuthCreateVerifyPage extends StatefulWidget {
|
||||
const AuthCreateVerifyPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AuthCreateVerifyPageState createState() => _AuthCreateVerifyPageState();
|
||||
}
|
||||
|
||||
class _AuthCreateVerifyPageState extends State<AuthCreateVerifyPage> {
|
||||
late final List<String> _mnemonicList;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Get.arguments['language'];
|
||||
var m = Get.arguments['mnemonic'] as List<String>;
|
||||
m.shuffle();
|
||||
_mnemonicList = m;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('校验助记词'),
|
||||
),
|
||||
body: _moArea(_mnemonicList),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _moArea(List<String> mnemonic) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 4.5 / 1,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
),
|
||||
itemCount: mnemonic.length,
|
||||
itemBuilder: (_, i) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: AppColors.border,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'${i + 1}. ${mnemonic[i]}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
58
lib/views/auth/import/index_page.dart
Normal file
58
lib/views/auth/import/index_page.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/utils/hd_wallet.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AuthImportPage extends StatefulWidget {
|
||||
const AuthImportPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AuthImportPage> createState() => _AuthImportPageState();
|
||||
}
|
||||
|
||||
class _AuthImportPageState extends State<AuthImportPage> {
|
||||
final TextEditingController _editingController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_editingController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('导入账户'),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _editingController,
|
||||
maxLines: 4,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入您的助记词',
|
||||
border: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: AppColors.border,
|
||||
width: 0.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Text('支持导入所有遵循BIP标准生成的助记词'),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
HDWallet.mnemonicToAddress(_editingController.text);
|
||||
},
|
||||
child: const Text('开始导入'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
lib/views/auth/index/index_page.dart
Normal file
37
lib/views/auth/index/index_page.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:chat/routes/auth_routes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AuthPage extends StatefulWidget {
|
||||
const AuthPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AuthPage> createState() => _AuthPageState();
|
||||
}
|
||||
|
||||
class _AuthPageState extends State<AuthPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('ZH-CHAT'),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.toNamed(AuthRoutes.create);
|
||||
},
|
||||
child: const Text('创建账户'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.toNamed(AuthRoutes.import);
|
||||
},
|
||||
child: const Text('导入账户'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AuthPage extends StatefulWidget {
|
||||
const AuthPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AuthPage> createState() => _AuthPageState();
|
||||
}
|
||||
|
||||
class _AuthPageState extends State<AuthPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user