2020-10-09 18:34:21 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
2020-11-03 22:29:06 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/validable_annotated_editable_text.dart';
|
2020-10-09 18:34:21 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/core/seed_validator.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/mnemonic_item.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-09-02 18:31:43 +00:00
|
|
|
import 'package:flutter/widgets.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class SeedWidget extends StatefulWidget {
|
2020-11-30 17:17:44 +00:00
|
|
|
SeedWidget({Key key, this.language, this.type}) : super(key: key);
|
2020-10-20 12:09:49 +00:00
|
|
|
|
|
|
|
final String language;
|
2020-11-30 17:17:44 +00:00
|
|
|
final WalletType type;
|
2020-01-08 12:26:34 +00:00
|
|
|
|
|
|
|
@override
|
2020-11-30 17:17:44 +00:00
|
|
|
SeedWidgetState createState() => SeedWidgetState(language, type);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class SeedWidgetState extends State<SeedWidget> {
|
2020-11-30 17:17:44 +00:00
|
|
|
SeedWidgetState(String language, this.type)
|
2020-10-13 21:11:04 +00:00
|
|
|
: controller = TextEditingController(),
|
|
|
|
focusNode = FocusNode(),
|
2020-10-20 12:09:49 +00:00
|
|
|
words = SeedValidator.getWordList(
|
2020-11-30 17:17:44 +00:00
|
|
|
type:type, language: language) {
|
2020-10-20 12:09:49 +00:00
|
|
|
focusNode.addListener(() {
|
|
|
|
setState(() {
|
|
|
|
if (!focusNode.hasFocus && controller.text.isEmpty) {
|
|
|
|
_showPlaceholder = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (focusNode.hasFocus) {
|
|
|
|
_showPlaceholder = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-01-16 16:05:07 +00:00
|
|
|
|
2020-10-13 21:11:04 +00:00
|
|
|
final TextEditingController controller;
|
|
|
|
final FocusNode focusNode;
|
2020-11-30 17:17:44 +00:00
|
|
|
final WalletType type;
|
2020-10-20 12:09:49 +00:00
|
|
|
List<String> words;
|
2020-10-13 21:11:04 +00:00
|
|
|
bool _showPlaceholder;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-10-13 21:11:04 +00:00
|
|
|
String get text => controller.text;
|
2020-01-16 16:05:07 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-10-13 21:11:04 +00:00
|
|
|
_showPlaceholder = true;
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 12:09:49 +00:00
|
|
|
void changeSeedLanguage(String language) {
|
|
|
|
setState(() {
|
|
|
|
words = SeedValidator.getWordList(
|
2020-11-30 17:17:44 +00:00
|
|
|
type: type, language: language);
|
2020-10-20 12:09:49 +00:00
|
|
|
});
|
2020-10-09 18:34:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2020-10-09 18:34:21 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Stack(children: [
|
|
|
|
SizedBox(height: 35),
|
2020-10-13 21:11:04 +00:00
|
|
|
if (_showPlaceholder)
|
2020-10-09 18:34:21 +00:00
|
|
|
Positioned(
|
|
|
|
top: 10,
|
|
|
|
left: 0,
|
|
|
|
child: Text('Enter your seed',
|
2020-06-20 07:10:00 +00:00
|
|
|
style: TextStyle(
|
2020-10-09 18:34:21 +00:00
|
|
|
fontSize: 16.0, color: Theme.of(context).hintColor))),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(right: 40, top: 10),
|
2020-11-13 14:58:28 +00:00
|
|
|
child: ValidatableAnnotatedEditableText(
|
2020-10-29 10:49:07 +00:00
|
|
|
cursorColor: Colors.blue,
|
|
|
|
backgroundCursorColor: Colors.blue,
|
2020-11-03 22:29:06 +00:00
|
|
|
validStyle: TextStyle(
|
|
|
|
color: Theme.of(context).primaryTextTheme.title.color,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
fontSize: 16),
|
|
|
|
invalidStyle: TextStyle(
|
2020-10-29 10:49:07 +00:00
|
|
|
fontSize: 16,
|
|
|
|
color: Colors.red,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
backgroundColor: Colors.transparent),
|
|
|
|
focusNode: focusNode,
|
|
|
|
controller: controller,
|
|
|
|
words: words,
|
|
|
|
textStyle: TextStyle(
|
|
|
|
color: Theme.of(context).primaryTextTheme.title.color,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
fontSize: 16),
|
|
|
|
)),
|
2020-10-09 18:34:21 +00:00
|
|
|
Positioned(
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: Container(
|
|
|
|
width: 34,
|
|
|
|
height: 34,
|
|
|
|
child: InkWell(
|
2020-11-03 22:29:06 +00:00
|
|
|
onTap: () async => _pasteText(),
|
2020-10-09 18:34:21 +00:00
|
|
|
child: Container(
|
2020-10-20 12:09:49 +00:00
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).hintColor,
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(6))),
|
|
|
|
child: Image.asset('assets/images/paste_ios.png',
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display1
|
|
|
|
.decorationColor)),
|
2020-10-09 18:34:21 +00:00
|
|
|
)))
|
|
|
|
]),
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(top: 15),
|
|
|
|
height: 1.0,
|
|
|
|
color: Theme.of(context).primaryTextTheme.title.backgroundColor),
|
|
|
|
]));
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
2020-10-20 12:09:49 +00:00
|
|
|
|
2020-11-03 22:29:06 +00:00
|
|
|
Future<void> _pasteText() async {
|
2020-10-20 12:09:49 +00:00
|
|
|
final value = await Clipboard.getData('text/plain');
|
|
|
|
|
|
|
|
if (value?.text?.isNotEmpty ?? false) {
|
|
|
|
setState(() {
|
|
|
|
_showPlaceholder = false;
|
|
|
|
controller.text = value.text;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|