stack_wallet/lib/widgets/custom_buttons/checkbox_text_button.dart

70 lines
1.6 KiB
Dart
Raw Permalink Normal View History

2024-05-01 23:15:04 +00:00
import 'package:flutter/material.dart';
2024-11-07 22:09:54 +00:00
import '../../utilities/text_styles.dart';
2024-05-01 23:15:04 +00:00
class CheckboxTextButton extends StatefulWidget {
2024-11-07 22:09:54 +00:00
const CheckboxTextButton({
super.key,
required this.label,
this.onChanged,
this.initialValue = false,
});
2024-05-01 23:15:04 +00:00
final String label;
final void Function(bool)? onChanged;
2024-11-07 22:09:54 +00:00
final bool initialValue;
2024-05-01 23:15:04 +00:00
@override
State<CheckboxTextButton> createState() => _CheckboxTextButtonState();
}
class _CheckboxTextButtonState extends State<CheckboxTextButton> {
2024-11-07 22:09:54 +00:00
late bool _value;
@override
void initState() {
super.initState();
_value = widget.initialValue;
}
2024-05-01 23:15:04 +00:00
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
_value = !_value;
});
widget.onChanged?.call(_value);
},
child: Container(
color: Colors.transparent,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
height: 26,
child: IgnorePointer(
child: Checkbox(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
value: _value,
onChanged: (_) {},
),
),
),
const SizedBox(
width: 12,
),
Expanded(
child: Text(
widget.label,
style: STextStyles.w500_14(context),
),
),
],
),
),
);
}
}