didvan checkbox component
This commit is contained in:
parent
af67f2d476
commit
eca4f56ad4
|
|
@ -0,0 +1,59 @@
|
|||
import 'package:didvan/widgets/didvan/text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DidvanCheckbox extends StatefulWidget {
|
||||
final String title;
|
||||
final bool? value;
|
||||
final void Function(bool value) onChanged;
|
||||
const DidvanCheckbox({
|
||||
Key? key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
}) : 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) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_value = !_value;
|
||||
});
|
||||
widget.onChanged(_value);
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _value,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_value = value ?? false;
|
||||
});
|
||||
widget.onChanged(_value);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
DidvanText(widget.title),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue