didvan-app/lib/views/widgets/didvan/checkbox.dart

60 lines
1.3 KiB
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 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),
],
),
),
);
}
}