mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-16 09:34:06 +01:00
Added the project
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/domain/common/contact.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/subaddress.dart';
|
||||
import 'package:cake_wallet/src/domain/common/qr_scanner.dart';
|
||||
|
||||
enum AddressTextFieldOption { qrCode, addressBook, subaddressList }
|
||||
|
||||
class AddressTextField extends StatelessWidget {
|
||||
static const prefixIconWidth = 34.0;
|
||||
static const prefixIconHeight = 34.0;
|
||||
static const spaceBetweenPrefixIcons = 10.0;
|
||||
|
||||
final TextEditingController controller;
|
||||
final bool isActive;
|
||||
final String placeholder;
|
||||
final Function(Uri) onURIScanned;
|
||||
final List<AddressTextFieldOption> options;
|
||||
final FormFieldValidator<String> validator;
|
||||
|
||||
AddressTextField(
|
||||
{@required this.controller,
|
||||
this.isActive = true,
|
||||
this.placeholder,
|
||||
this.options = const [
|
||||
AddressTextFieldOption.qrCode,
|
||||
AddressTextFieldOption.addressBook
|
||||
],
|
||||
this.onURIScanned,
|
||||
this.validator});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
onFieldSubmitted: (_) => FocusScope.of(context).unfocus(),
|
||||
enabled: isActive,
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: SizedBox(
|
||||
width: prefixIconWidth * options.length +
|
||||
(spaceBetweenPrefixIcons * options.length),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(width: 5),
|
||||
if (this.options.contains(AddressTextFieldOption.qrCode)) ...[
|
||||
Container(
|
||||
width: prefixIconWidth,
|
||||
height: prefixIconHeight,
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: InkWell(
|
||||
onTap: () async => _presentQRScanner(context),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Palette.wildDarkBlueWithOpacity,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(8))),
|
||||
child: Image.asset('assets/images/qr_code_icon.png')),
|
||||
))
|
||||
],
|
||||
if (this
|
||||
.options
|
||||
.contains(AddressTextFieldOption.addressBook)) ...[
|
||||
Container(
|
||||
width: prefixIconWidth,
|
||||
height: prefixIconHeight,
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: InkWell(
|
||||
onTap: () async => _presetAddressBookPicker(context),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Palette.wildDarkBlueWithOpacity,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(8))),
|
||||
child: Image.asset(
|
||||
'assets/images/address_book_icon.png')),
|
||||
))
|
||||
],
|
||||
if (this
|
||||
.options
|
||||
.contains(AddressTextFieldOption.subaddressList)) ...[
|
||||
Container(
|
||||
width: prefixIconWidth,
|
||||
height: prefixIconHeight,
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: InkWell(
|
||||
onTap: () async => _presetSubaddressListPicker(context),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Palette.wildDarkBlueWithOpacity,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(8))),
|
||||
child: Image.asset(
|
||||
'assets/images/receive_icon_raw.png')),
|
||||
))
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
hintStyle: TextStyle(color: Theme.of(context).hintColor),
|
||||
hintText: placeholder ?? S.current.widgets_address,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Palette.cakeGreen, width: 2.0)),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Theme.of(context).focusColor, width: 1.0)),
|
||||
),
|
||||
validator: validator,
|
||||
);
|
||||
}
|
||||
|
||||
Future _presentQRScanner(BuildContext context) async {
|
||||
try {
|
||||
String code = await presentQRScanner();
|
||||
var uri = Uri.parse(code);
|
||||
var address = '';
|
||||
|
||||
if (uri == null) {
|
||||
controller.text = code;
|
||||
return;
|
||||
}
|
||||
|
||||
address = uri.path;
|
||||
controller.text = address;
|
||||
|
||||
if (onURIScanned != null) {
|
||||
onURIScanned(uri);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future _presetAddressBookPicker(BuildContext context) async {
|
||||
final contact = await Navigator.of(context, rootNavigator: true)
|
||||
.pushNamed(Routes.pickerAddressBook);
|
||||
|
||||
if (contact is Contact && contact.address != null) {
|
||||
controller.text = contact.address;
|
||||
}
|
||||
}
|
||||
|
||||
Future _presetSubaddressListPicker(BuildContext context) async {
|
||||
final subaddress = await Navigator.of(context, rootNavigator: true)
|
||||
.pushNamed(Routes.subaddressList);
|
||||
|
||||
if (subaddress is Subaddress && subaddress.address != null) {
|
||||
controller.text = subaddress.address;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/get_height_by_date.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
|
||||
class BlockchainHeightWidget extends StatefulWidget {
|
||||
BlockchainHeightWidget({GlobalKey key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => BlockchainHeightState();
|
||||
}
|
||||
|
||||
class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||
final dateController = TextEditingController();
|
||||
final restoreHeightController = TextEditingController();
|
||||
int get height => _height;
|
||||
int _height = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
restoreHeightController.addListener(() => _height =
|
||||
restoreHeightController.text != null
|
||||
? int.parse(restoreHeightController.text)
|
||||
: 0);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 20.0, bottom: 10.0),
|
||||
child: TextFormField(
|
||||
style: TextStyle(fontSize: 14.0),
|
||||
controller: restoreHeightController,
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
signed: false, decimal: false),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: TextStyle(color: Theme.of(context).hintColor),
|
||||
hintText: S.of(context).widgets_restore_from_blockheight,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Palette.cakeGreen, width: 2.0)),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).focusColor, width: 1.0))),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 15, bottom: 15),
|
||||
child: Text(
|
||||
S.of(context).widgets_or,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).primaryTextTheme.title.color),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: Container(
|
||||
child: InkWell(
|
||||
onTap: () => _selectDate(context),
|
||||
child: IgnorePointer(
|
||||
child: TextFormField(
|
||||
style: TextStyle(fontSize: 14.0),
|
||||
decoration: InputDecoration(
|
||||
hintStyle:
|
||||
TextStyle(color: Theme.of(context).hintColor),
|
||||
hintText: S.of(context).widgets_restore_from_date,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Palette.cakeGreen,
|
||||
width: 2.0)),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).focusColor,
|
||||
width: 1.0))),
|
||||
controller: dateController,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future _selectDate(BuildContext context) async {
|
||||
final now = DateTime.now();
|
||||
final DateTime date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: now.subtract(Duration(days: 1)),
|
||||
firstDate: DateTime(2014, DateTime.april),
|
||||
lastDate: now);
|
||||
|
||||
if (date != null) {
|
||||
final height = getHeigthByDate(date: date);
|
||||
|
||||
setState(() {
|
||||
dateController.text = DateFormat('yyyy-MM-dd').format(date);
|
||||
restoreHeightController.text = '$height';
|
||||
_height = height;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:cake_wallet/theme_changer.dart';
|
||||
import 'package:cake_wallet/themes.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class NavBar extends StatelessWidget implements ObstructingPreferredSizeWidget {
|
||||
static const _originalHeight = 44.0; // iOS nav bar height
|
||||
static const _height = 60.0;
|
||||
|
||||
factory NavBar.withShadow(
|
||||
{BuildContext context,
|
||||
Widget leading,
|
||||
Widget middle,
|
||||
Widget trailing,
|
||||
Color backgroundColor}) {
|
||||
final _themeChanger = Provider.of<ThemeChanger>(context);
|
||||
final _isDarkTheme = _themeChanger.getTheme() == Themes.darkTheme;
|
||||
|
||||
return NavBar._internal(
|
||||
leading: leading,
|
||||
middle: middle,
|
||||
trailing: trailing,
|
||||
height: 80,
|
||||
backgroundColor:
|
||||
_isDarkTheme ? Theme.of(context).backgroundColor : backgroundColor,
|
||||
decoration: BoxDecoration(
|
||||
color: _isDarkTheme
|
||||
? Theme.of(context).backgroundColor
|
||||
: backgroundColor,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color.fromRGBO(132, 141, 198, 0.11),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2))
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
factory NavBar(
|
||||
{BuildContext context,
|
||||
Widget leading,
|
||||
Widget middle,
|
||||
Widget trailing,
|
||||
Color backgroundColor}) {
|
||||
final _themeChanger = Provider.of<ThemeChanger>(context);
|
||||
final _isDarkTheme = _themeChanger.getTheme() == Themes.darkTheme;
|
||||
|
||||
return NavBar._internal(
|
||||
leading: leading,
|
||||
middle: middle,
|
||||
trailing: trailing,
|
||||
height: _height,
|
||||
backgroundColor:
|
||||
_isDarkTheme ? Theme.of(context).backgroundColor : backgroundColor);
|
||||
}
|
||||
|
||||
final Widget leading;
|
||||
final Widget middle;
|
||||
final Widget trailing;
|
||||
final Color backgroundColor;
|
||||
final BoxDecoration decoration;
|
||||
final double height;
|
||||
|
||||
NavBar._internal(
|
||||
{this.leading,
|
||||
this.middle,
|
||||
this.trailing,
|
||||
this.backgroundColor,
|
||||
this.decoration,
|
||||
this.height = _height});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pad = height - _originalHeight;
|
||||
final paddingTop = pad / 2;
|
||||
final _paddingBottom = (pad / 2);
|
||||
|
||||
return Container(
|
||||
decoration: decoration ?? BoxDecoration(color: backgroundColor),
|
||||
padding:
|
||||
EdgeInsetsDirectional.only(bottom: _paddingBottom, top: paddingTop),
|
||||
child: CupertinoNavigationBar(
|
||||
leading: leading,
|
||||
middle: middle,
|
||||
trailing: trailing,
|
||||
backgroundColor: backgroundColor,
|
||||
border: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Size get preferredSize => Size.fromHeight(height);
|
||||
|
||||
@override
|
||||
bool shouldFullyObstruct(BuildContext context) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Picker<Item extends Object> extends StatelessWidget {
|
||||
final int selectedAtIndex;
|
||||
final List<Item> items;
|
||||
final String title;
|
||||
final double pickerHeight;
|
||||
final Function(Item) onItemSelected;
|
||||
|
||||
Picker(
|
||||
{@required this.selectedAtIndex,
|
||||
@required this.items,
|
||||
@required this.title,
|
||||
this.pickerHeight = 300,
|
||||
this.onItemSelected});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: Colors.white.withOpacity(0.55)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => null,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: pickerHeight,
|
||||
color: Theme.of(context).backgroundColor,
|
||||
child: ListView.separated(
|
||||
itemCount: items.length + 1,
|
||||
separatorBuilder: (_, index) => index == 0
|
||||
? SizedBox()
|
||||
: Divider(
|
||||
height: 1,
|
||||
color: Color.fromRGBO(235, 238, 242, 1)),
|
||||
itemBuilder: (_, index) {
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
height: 100,
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).backgroundColor,
|
||||
child: Center(
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 26,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontFamily: 'Lato',
|
||||
decoration: TextDecoration.none,
|
||||
color: Theme.of(context).primaryTextTheme.caption.color
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
index -= 1;
|
||||
final item = items[index];
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (onItemSelected == null) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
onItemSelected(item);
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
padding: EdgeInsets.only(top: 18, bottom: 18),
|
||||
child: Center(
|
||||
child: Text(
|
||||
item.toString(),
|
||||
style: TextStyle(
|
||||
decoration: TextDecoration.none,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontFamily: 'Lato',
|
||||
color: index == selectedAtIndex
|
||||
? Color.fromRGBO(138, 80, 255, 1)
|
||||
: Theme.of(context).primaryTextTheme.caption.color),
|
||||
)),
|
||||
),
|
||||
);
|
||||
},
|
||||
)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
|
||||
class PrimaryButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final Color color;
|
||||
final Color borderColor;
|
||||
final String text;
|
||||
|
||||
const PrimaryButton(
|
||||
{@required this.onPressed,
|
||||
@required this.text,
|
||||
@required this.color,
|
||||
@required this.borderColor});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return ButtonTheme(
|
||||
minWidth: double.infinity,
|
||||
height: 56.0,
|
||||
child: FlatButton(
|
||||
onPressed: onPressed,
|
||||
color: color,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
child: Text(text,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Theme.of(context).primaryTextTheme.button.color)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class LoadingPrimaryButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final Color color;
|
||||
final Color borderColor;
|
||||
final bool isLoading;
|
||||
final bool isDisabled;
|
||||
final String text;
|
||||
|
||||
const LoadingPrimaryButton(
|
||||
{@required this.onPressed,
|
||||
@required this.text,
|
||||
@required this.color,
|
||||
@required this.borderColor,
|
||||
this.isDisabled = false,
|
||||
this.isLoading = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return ButtonTheme(
|
||||
minWidth: double.infinity,
|
||||
height: 56.0,
|
||||
child: FlatButton(
|
||||
onPressed: (isLoading || isDisabled) ? null : onPressed,
|
||||
color: color,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
child: isLoading
|
||||
? CupertinoActivityIndicator(animating: true)
|
||||
: Text(text,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Theme.of(context).primaryTextTheme.button.color)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class PrimaryIconButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final IconData iconData;
|
||||
final Color color;
|
||||
final Color borderColor;
|
||||
final Color iconColor;
|
||||
final Color iconBackgroundColor;
|
||||
final String text;
|
||||
|
||||
const PrimaryIconButton({
|
||||
@required this.onPressed,
|
||||
@required this.iconData,
|
||||
@required this.text,
|
||||
@required this.color,
|
||||
@required this.borderColor,
|
||||
@required this.iconColor,
|
||||
@required this.iconBackgroundColor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return ButtonTheme(
|
||||
minWidth: double.infinity,
|
||||
height: 56.0,
|
||||
child: FlatButton(
|
||||
onPressed: onPressed,
|
||||
color: color,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 28.0,
|
||||
height: 56.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle, color: iconBackgroundColor),
|
||||
child: Icon(iconData, color: iconColor, size: 22.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
height: 56.0,
|
||||
child: Center(
|
||||
child: Text(text,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Theme.of(context).primaryTextTheme.button.color)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class PrimaryImageButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final Image image;
|
||||
final Color color;
|
||||
final Color borderColor;
|
||||
final Color iconColor;
|
||||
final String text;
|
||||
|
||||
const PrimaryImageButton(
|
||||
{@required this.onPressed,
|
||||
@required this.image,
|
||||
@required this.text,
|
||||
this.color = Palette.purple,
|
||||
this.borderColor = Palette.deepPink,
|
||||
this.iconColor = Colors.black});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ButtonTheme(
|
||||
minWidth: double.infinity,
|
||||
height: 58.0,
|
||||
child: FlatButton(
|
||||
onPressed: onPressed,
|
||||
color: color,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(12.0)),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 28.0,
|
||||
height: 56.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle, color: Colors.transparent),
|
||||
child: image,
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
height: 56.0,
|
||||
child: Center(
|
||||
child: Text(text, style: TextStyle(fontSize: 18.0,
|
||||
color: Theme.of(context).primaryTextTheme.button.color
|
||||
)),
|
||||
),
|
||||
)
|
||||
]))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ScrollableWithBottomSection extends StatefulWidget {
|
||||
final Widget content;
|
||||
final Widget bottomSection;
|
||||
final EdgeInsets contentPadding;
|
||||
final EdgeInsets bottomSectionPadding;
|
||||
|
||||
ScrollableWithBottomSection(
|
||||
{this.content,
|
||||
this.bottomSection,
|
||||
this.contentPadding,
|
||||
this.bottomSectionPadding});
|
||||
|
||||
@override
|
||||
ScrollableWithBottomSectionState createState() =>
|
||||
ScrollableWithBottomSectionState();
|
||||
}
|
||||
|
||||
class ScrollableWithBottomSectionState
|
||||
extends State<ScrollableWithBottomSection> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
return SingleChildScrollView(
|
||||
// physics:
|
||||
// const AlwaysScrollableScrollPhysics(), // const NeverScrollableScrollPhysics(), //
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.heightConstraints().maxHeight),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: widget.contentPadding ??
|
||||
EdgeInsets.only(left: 20, right: 20),
|
||||
child: widget.content,
|
||||
),
|
||||
Padding(
|
||||
padding: widget.bottomSectionPadding ??
|
||||
EdgeInsets.only(bottom: 20, right: 20, left: 20),
|
||||
child: widget.bottomSection)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/mnemonics/english.dart';
|
||||
import 'package:cake_wallet/src/domain/common/mnemotic_item.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
class SeedWidget extends StatefulWidget {
|
||||
final Function(List<MnemoticItem>) onMnemoticChange;
|
||||
|
||||
SeedWidget({Key key, this.onMnemoticChange}) : super(key: key);
|
||||
|
||||
SeedWidgetState createState() => SeedWidgetState();
|
||||
}
|
||||
|
||||
class SeedWidgetState extends State<SeedWidget> {
|
||||
List<MnemoticItem> items = <MnemoticItem>[];
|
||||
final _seedController = TextEditingController();
|
||||
MnemoticItem selectedItem;
|
||||
bool isValid;
|
||||
String errorMessage;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
isValid = true;
|
||||
_seedController.addListener(() => mnemoticFromText(_seedController.text));
|
||||
}
|
||||
|
||||
void addMnemotic(String text) {
|
||||
setState(() => items.add(MnemoticItem(
|
||||
text: text.trim().toLowerCase(), dic: EnglishMnemonics.words)));
|
||||
_seedController.text = '';
|
||||
|
||||
if (widget.onMnemoticChange != null) {
|
||||
widget.onMnemoticChange(items);
|
||||
}
|
||||
}
|
||||
|
||||
void deleteMnemotic(MnemoticItem item) {
|
||||
setState(() => items.remove(item));
|
||||
|
||||
if (widget.onMnemoticChange != null) {
|
||||
widget.onMnemoticChange(items);
|
||||
}
|
||||
}
|
||||
|
||||
void mnemoticFromText(String text) {
|
||||
final splitted = text.split(' ');
|
||||
|
||||
if (splitted.length >= 2) {
|
||||
for (final text in splitted) {
|
||||
if (text == ' ' || text.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectedItem != null) {
|
||||
editTextOfSelectedMnemotic(text);
|
||||
} else {
|
||||
addMnemotic(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void selectMnemotic(MnemoticItem item) {
|
||||
setState(() => selectedItem = item);
|
||||
_seedController
|
||||
..text = item.text
|
||||
..selection = TextSelection.collapsed(offset: item.text.length);
|
||||
}
|
||||
|
||||
void onMnemoticTap(MnemoticItem item) {
|
||||
if (selectedItem == item) {
|
||||
setState(() => selectedItem = null);
|
||||
_seedController.text = '';
|
||||
return;
|
||||
}
|
||||
|
||||
selectMnemotic(item);
|
||||
}
|
||||
|
||||
void editTextOfSelectedMnemotic(String text) {
|
||||
setState(() => selectedItem.changeText(text));
|
||||
selectedItem = null;
|
||||
_seedController.text = '';
|
||||
|
||||
if (widget.onMnemoticChange != null) {
|
||||
widget.onMnemoticChange(items);
|
||||
}
|
||||
}
|
||||
|
||||
void onFieldSubmitted(String text) {
|
||||
if (text.isEmpty || text == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedItem != null) {
|
||||
editTextOfSelectedMnemotic(text);
|
||||
} else {
|
||||
addMnemotic(text);
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
setState(() {
|
||||
items = [];
|
||||
_seedController.text = '';
|
||||
|
||||
if (widget.onMnemoticChange != null) {
|
||||
widget.onMnemoticChange(items);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void invalidate() {
|
||||
setState(() => isValid = false);
|
||||
}
|
||||
|
||||
void validated() {
|
||||
setState(() => isValid = true);
|
||||
}
|
||||
|
||||
void setErrorMessage(String errorMessage) {
|
||||
setState(() => this.errorMessage = errorMessage);
|
||||
}
|
||||
|
||||
void replaceText(String text) {
|
||||
setState(() => items = []);
|
||||
mnemoticFromText(text);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: Column(children: [
|
||||
TextFormField(
|
||||
onFieldSubmitted: (text) => onFieldSubmitted(text),
|
||||
style: TextStyle(fontSize: 14.0),
|
||||
controller: _seedController,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: SizedBox(
|
||||
width: 65,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () {
|
||||
clear();
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
child: Container(
|
||||
height: 20,
|
||||
width: 20,
|
||||
padding: EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
color: Palette.wildDarkBlueWithOpacity,
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
child: Image.asset(
|
||||
'assets/images/x.png',
|
||||
color: Palette.wildDarkBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () async => Clipboard.getData('text/plain')
|
||||
.then((clipboard) => replaceText(clipboard.text)),
|
||||
child: Container(
|
||||
height: 35,
|
||||
width: 35,
|
||||
padding: EdgeInsets.all(7),
|
||||
decoration: BoxDecoration(
|
||||
color: Palette.wildDarkBlueWithOpacity,
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
child: Image.asset('assets/images/paste_button.png',
|
||||
height: 5, width: 5, color: Palette.wildDarkBlue),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
errorText: errorMessage,
|
||||
hintStyle: TextStyle(color: Theme.of(context).hintColor),
|
||||
hintText: S.of(context).widgets_seed,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Palette.cakeGreen, width: 2.0)),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color:
|
||||
isValid ? Theme.of(context).focusColor : Palette.red,
|
||||
width: 1.0))),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: GridView.count(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 3,
|
||||
childAspectRatio: 3.3,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
children: List.generate(items.length, (index) {
|
||||
final item = items[index];
|
||||
final isValid = item.isCorrect();
|
||||
final isSelected = selectedItem == item;
|
||||
|
||||
return InkWell(
|
||||
onTap: () => onMnemoticTap(item),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isValid ? Palette.brightBlue : Palette.red,
|
||||
border: Border.all(
|
||||
color:
|
||||
isSelected ? Palette.violet : Colors.transparent),
|
||||
borderRadius: BorderRadius.circular(15.0)),
|
||||
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
item.toString(),
|
||||
style: TextStyle(
|
||||
color:
|
||||
isValid ? Palette.blueGrey : Palette.lightGrey,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => deleteMnemotic(item),
|
||||
child: Image.asset(
|
||||
'assets/images/x.png',
|
||||
height: 15,
|
||||
width: 15,
|
||||
color: Palette.wildDarkBlue,
|
||||
))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class StandartCloseButton extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 37,
|
||||
width: 37,
|
||||
child: FlatButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Image.asset('assets/images/close_button.png')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StandartSwitch extends StatefulWidget {
|
||||
|
||||
final bool value;
|
||||
final VoidCallback onTaped;
|
||||
|
||||
const StandartSwitch({
|
||||
@required this.value,
|
||||
@required this.onTaped});
|
||||
|
||||
@override
|
||||
createState() => StandartSwitchState();
|
||||
|
||||
}
|
||||
|
||||
class StandartSwitchState extends State<StandartSwitch> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return GestureDetector(
|
||||
onTap: widget.onTaped,
|
||||
child: AnimatedContainer(
|
||||
padding: EdgeInsets.only(left: 4.0, right: 4.0),
|
||||
alignment: widget.value
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
duration: Duration(milliseconds: 250),
|
||||
width: 55.0,
|
||||
height: 33.0,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).toggleButtonsTheme.color,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).toggleButtonsTheme.borderColor
|
||||
),
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(10.0))),
|
||||
child: Container(
|
||||
width: 25.0,
|
||||
height: 25.0,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.value
|
||||
? Theme.of(context).toggleButtonsTheme.selectedColor
|
||||
: Theme.of(context).toggleButtonsTheme.disabledColor,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(8.0))),
|
||||
child: Icon(widget.value
|
||||
? Icons.check
|
||||
: Icons.close,
|
||||
color: Colors.white,
|
||||
size: 16.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user