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