74 lines
1.8 KiB
Dart
74 lines
1.8 KiB
Dart
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DidvanCheckbox extends StatefulWidget {
|
|
final String title;
|
|
final bool? value;
|
|
final double size;
|
|
final Color? color;
|
|
final void Function(bool value) onChanged;
|
|
const DidvanCheckbox({
|
|
Key? key,
|
|
required this.title,
|
|
required this.value,
|
|
required this.onChanged, this.size = 15, this.color,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<DidvanCheckbox> createState() => _DidvanCheckboxState();
|
|
}
|
|
|
|
class _DidvanCheckboxState extends State<DidvanCheckbox> {
|
|
bool _value = false;
|
|
|
|
@override
|
|
void initState() {
|
|
if (widget.value != null) {
|
|
_value = widget.value!;
|
|
}
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Color? color = widget.color;
|
|
color ??= Theme.of(context).colorScheme.text;
|
|
|
|
return GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
_value = !_value;
|
|
});
|
|
widget.onChanged(_value);
|
|
},
|
|
child: Container(
|
|
color: Colors.transparent,
|
|
child: Row(
|
|
children: [
|
|
Transform.scale(
|
|
scale: widget.size ==15 ? 1 : 0.8,
|
|
child: Checkbox(
|
|
activeColor: widget.color,
|
|
|
|
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
|
|
side: BorderSide(color: color, width: 1.5),
|
|
value: _value,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_value = value ?? false;
|
|
});
|
|
widget.onChanged(_value);
|
|
},
|
|
),
|
|
), DidvanText(widget.title,fontSize: widget.size,color: color, ),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|