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';
|
|
|
|
import 'package:cake_wallet/src/domain/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-06-20 07:10:00 +00:00
|
|
|
BlockchainHeightWidget({GlobalKey key, this.onHeightChange})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
final Function(int) onHeightChange;
|
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(() {
|
|
|
|
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(
|
|
|
|
padding: EdgeInsets.only(top: 20.0, bottom: 10.0),
|
2020-09-04 10:40:28 +00:00
|
|
|
child: BaseTextFormField(
|
2020-01-04 19:31:52 +00:00
|
|
|
controller: restoreHeightController,
|
|
|
|
keyboardType: TextInputType.numberWithOptions(
|
|
|
|
signed: false, decimal: false),
|
2020-09-04 10:40:28 +00:00
|
|
|
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-09-04 10:40:28 +00:00
|
|
|
child: BaseTextFormField(
|
2020-01-04 19:31:52 +00:00
|
|
|
controller: dateController,
|
2020-09-04 10:40:28 +00:00
|
|
|
hintText: S.of(context).widgets_restore_from_date,
|
|
|
|
)
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _selectDate(BuildContext context) async {
|
|
|
|
final now = DateTime.now();
|
2020-06-20 07:10:00 +00:00
|
|
|
final date = await showDatePicker(
|
2020-01-04 19:31:52 +00:00
|
|
|
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';
|
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
|
|
|
}
|