2020-10-01 17:29:06 +00:00
|
|
|
import 'package:cake_wallet/utils/date_picker.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/monero/get_height_by_date.dart';
|
2020-09-04 10:40:28 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class BlockchainHeightWidget extends StatefulWidget {
|
2020-11-12 19:03:57 +00:00
|
|
|
BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode,
|
|
|
|
this.onHeightOrDateEntered})
|
2020-06-20 07:10:00 +00:00
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
final Function(int) onHeightChange;
|
2020-11-12 19:03:57 +00:00
|
|
|
final Function(bool) onHeightOrDateEntered;
|
2020-10-20 12:09:49 +00:00
|
|
|
final FocusNode focusNode;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => BlockchainHeightState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|
|
|
final dateController = TextEditingController();
|
|
|
|
final restoreHeightController = TextEditingController();
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
int get height => _height;
|
|
|
|
int _height = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2020-06-20 07:10:00 +00:00
|
|
|
restoreHeightController.addListener(() {
|
2020-11-12 19:03:57 +00:00
|
|
|
if (restoreHeightController.text.isNotEmpty) {
|
|
|
|
widget.onHeightOrDateEntered?.call(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
widget.onHeightOrDateEntered?.call(false);
|
|
|
|
dateController.text = '';
|
|
|
|
}
|
2020-06-20 07:10:00 +00:00
|
|
|
try {
|
|
|
|
_changeHeight(restoreHeightController.text != null &&
|
|
|
|
restoreHeightController.text.isNotEmpty
|
2020-01-04 19:31:52 +00:00
|
|
|
? int.parse(restoreHeightController.text)
|
|
|
|
: 0);
|
2020-06-20 07:10:00 +00:00
|
|
|
} catch (_) {
|
|
|
|
_changeHeight(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
child: Container(
|
2020-10-20 12:09:49 +00:00
|
|
|
padding: EdgeInsets.only(top: 20.0, bottom: 10.0),
|
|
|
|
child: BaseTextFormField(
|
|
|
|
focusNode: widget.focusNode,
|
|
|
|
controller: restoreHeightController,
|
|
|
|
keyboardType: TextInputType.numberWithOptions(
|
|
|
|
signed: false, decimal: false),
|
|
|
|
hintText: S.of(context).widgets_restore_from_blockheight,
|
|
|
|
)))
|
2020-01-04 19:31:52 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 15, bottom: 15),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).widgets_or,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
2020-09-04 10:40:28 +00:00
|
|
|
fontWeight: FontWeight.w500,
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme.title.color),
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
child: Container(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => _selectDate(context),
|
|
|
|
child: IgnorePointer(
|
2020-10-20 12:09:49 +00:00
|
|
|
child: BaseTextFormField(
|
|
|
|
controller: dateController,
|
|
|
|
hintText: S.of(context).widgets_restore_from_date,
|
|
|
|
)),
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
2020-11-12 19:03:57 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 40, right: 40, top: 24),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).restore_from_date_or_blockheight,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
color: Theme.of(context).hintColor
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-01-04 19:31:52 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _selectDate(BuildContext context) async {
|
|
|
|
final now = DateTime.now();
|
2020-10-01 17:29:06 +00:00
|
|
|
final date = await getDate(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
|
|
|
initialDate: now.subtract(Duration(days: 1)),
|
2020-11-12 15:46:05 +00:00
|
|
|
firstDate: DateTime(2014, DateTime.may),
|
2020-01-04 19:31:52 +00:00
|
|
|
lastDate: now);
|
|
|
|
|
|
|
|
if (date != null) {
|
|
|
|
final height = getHeigthByDate(date: date);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
dateController.text = DateFormat('yyyy-MM-dd').format(date);
|
|
|
|
restoreHeightController.text = '$height';
|
2020-06-20 07:10:00 +00:00
|
|
|
_changeHeight(height);
|
2020-01-04 19:31:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
void _changeHeight(int height) {
|
|
|
|
_height = height;
|
|
|
|
widget.onHeightChange?.call(height);
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|