mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
make checkbox stateless
This commit is contained in:
parent
c57507e530
commit
b536973077
4 changed files with 11 additions and 39 deletions
|
@ -103,7 +103,7 @@ class FilterWidget extends StatelessWidget {
|
||||||
gradientBackground: true,
|
gradientBackground: true,
|
||||||
borderColor: Theme.of(context).dividerColor,
|
borderColor: Theme.of(context).dividerColor,
|
||||||
iconColor: Colors.white,
|
iconColor: Colors.white,
|
||||||
onChanged: (bool val){},
|
onChanged: (value) => item.onChanged(),
|
||||||
))
|
))
|
||||||
: GestureDetector(
|
: GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
|
|
@ -40,7 +40,6 @@ class ExchangePage extends BasePage {
|
||||||
final ExchangeViewModel exchangeViewModel;
|
final ExchangeViewModel exchangeViewModel;
|
||||||
final depositKey = GlobalKey<ExchangeCardState>();
|
final depositKey = GlobalKey<ExchangeCardState>();
|
||||||
final receiveKey = GlobalKey<ExchangeCardState>();
|
final receiveKey = GlobalKey<ExchangeCardState>();
|
||||||
final checkBoxKey = GlobalKey<StandardCheckboxState>();
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _depositAmountFocus = FocusNode();
|
final _depositAmountFocus = FocusNode();
|
||||||
final _depositAddressFocus = FocusNode();
|
final _depositAddressFocus = FocusNode();
|
||||||
|
@ -339,7 +338,6 @@ class ExchangePage extends BasePage {
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
StandardCheckbox(
|
StandardCheckbox(
|
||||||
key: checkBoxKey,
|
|
||||||
value: exchangeViewModel.isFixedRateMode,
|
value: exchangeViewModel.isFixedRateMode,
|
||||||
caption: S.of(context).fixed_rate,
|
caption: S.of(context).fixed_rate,
|
||||||
onChanged: (value) =>
|
onChanged: (value) =>
|
||||||
|
@ -682,12 +680,6 @@ class ExchangePage extends BasePage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction((_) => exchangeViewModel.isFixedRateMode, (bool value) {
|
|
||||||
if (checkBoxKey.currentState!.value != exchangeViewModel.isFixedRateMode) {
|
|
||||||
checkBoxKey.currentState!.value = exchangeViewModel.isFixedRateMode;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
depositAddressController.addListener(
|
depositAddressController.addListener(
|
||||||
() => exchangeViewModel.depositAddress = depositAddressController.text);
|
() => exchangeViewModel.depositAddress = depositAddressController.text);
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,14 @@ import 'dart:ui';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class StandardCheckbox extends StatefulWidget {
|
class StandardCheckbox extends StatelessWidget {
|
||||||
StandardCheckbox({
|
StandardCheckbox({
|
||||||
Key? key,
|
|
||||||
required this.value,
|
required this.value,
|
||||||
this.caption = '',
|
this.caption = '',
|
||||||
this.gradientBackground = false,
|
this.gradientBackground = false,
|
||||||
this.borderColor,
|
this.borderColor,
|
||||||
this.iconColor,
|
this.iconColor,
|
||||||
required this.onChanged})
|
required this.onChanged});
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
final bool value;
|
final bool value;
|
||||||
final String caption;
|
final String caption;
|
||||||
|
@ -20,21 +18,7 @@ class StandardCheckbox extends StatefulWidget {
|
||||||
final Color? iconColor;
|
final Color? iconColor;
|
||||||
final Function(bool) onChanged;
|
final Function(bool) onChanged;
|
||||||
|
|
||||||
@override
|
|
||||||
StandardCheckboxState createState() =>
|
|
||||||
StandardCheckboxState(value, caption, onChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
class StandardCheckboxState extends State<StandardCheckbox> {
|
|
||||||
StandardCheckboxState(this.value, this.caption, this.onChanged);
|
|
||||||
|
|
||||||
bool value;
|
|
||||||
String caption;
|
|
||||||
Function(bool) onChanged;
|
|
||||||
|
|
||||||
void changeValue(bool newValue) {
|
|
||||||
setState(() => value = newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -45,7 +29,7 @@ class StandardCheckboxState extends State<StandardCheckbox> {
|
||||||
], begin: Alignment.centerLeft, end: Alignment.centerRight);
|
], begin: Alignment.centerLeft, end: Alignment.centerRight);
|
||||||
|
|
||||||
final boxBorder = Border.all(
|
final boxBorder = Border.all(
|
||||||
color: widget.borderColor ?? Theme.of(context)
|
color: borderColor ?? Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.caption!
|
.caption!
|
||||||
.color!,
|
.color!,
|
||||||
|
@ -53,8 +37,8 @@ class StandardCheckboxState extends State<StandardCheckbox> {
|
||||||
|
|
||||||
|
|
||||||
final checkedBoxDecoration = BoxDecoration(
|
final checkedBoxDecoration = BoxDecoration(
|
||||||
gradient: widget.gradientBackground ? baseGradient : null,
|
gradient: gradientBackground ? baseGradient : null,
|
||||||
border: widget.gradientBackground ? null : boxBorder,
|
border: gradientBackground ? null : boxBorder,
|
||||||
borderRadius: BorderRadius.all(
|
borderRadius: BorderRadius.all(
|
||||||
Radius.circular(8.0)));
|
Radius.circular(8.0)));
|
||||||
|
|
||||||
|
@ -64,11 +48,7 @@ class StandardCheckboxState extends State<StandardCheckbox> {
|
||||||
Radius.circular(8.0)));
|
Radius.circular(8.0)));
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () => onChanged(!value),
|
||||||
value = !value;
|
|
||||||
onChanged(value);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
@ -80,7 +60,7 @@ class StandardCheckboxState extends State<StandardCheckbox> {
|
||||||
child: value
|
child: value
|
||||||
? Icon(
|
? Icon(
|
||||||
Icons.check,
|
Icons.check,
|
||||||
color: widget.iconColor ?? Colors.blue,
|
color: iconColor ?? Colors.blue,
|
||||||
size: 20.0,
|
size: 20.0,
|
||||||
)
|
)
|
||||||
: Offstage(),
|
: Offstage(),
|
||||||
|
|
|
@ -61,15 +61,15 @@ abstract class DashboardViewModelBase with Store {
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: transactionFilterStore.displayAll,
|
value: transactionFilterStore.displayAll,
|
||||||
caption: S.current.all_transactions,
|
caption: S.current.all_transactions,
|
||||||
onChanged: () => transactionFilterStore.toggleIAll()),
|
onChanged: transactionFilterStore.toggleIAll),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: transactionFilterStore.displayIncoming,
|
value: transactionFilterStore.displayIncoming,
|
||||||
caption: S.current.incoming,
|
caption: S.current.incoming,
|
||||||
onChanged: () => transactionFilterStore.toggleIncoming()),
|
onChanged:transactionFilterStore.toggleIncoming),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: transactionFilterStore.displayOutgoing,
|
value: transactionFilterStore.displayOutgoing,
|
||||||
caption: S.current.outgoing,
|
caption: S.current.outgoing,
|
||||||
onChanged: () => transactionFilterStore.toggleOutgoing()),
|
onChanged: transactionFilterStore.toggleOutgoing),
|
||||||
// FilterItem(
|
// FilterItem(
|
||||||
// value: () => false,
|
// value: () => false,
|
||||||
// caption: S.current.transactions_by_date,
|
// caption: S.current.transactions_by_date,
|
||||||
|
|
Loading…
Reference in a new issue