Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
5
Indexable
Never
import 'package:flutter/material.dart';

class TaskTile extends StatefulWidget {
  @override
  State<TaskTile> createState() => _TaskTileState();

}

class _TaskTileState extends State<TaskTile> {
  void checkboxCallback = (bool checkboxState) {
    setState(() {
      isChecked = checkboxState;
    });
  };
  bool isChecked = false;

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(
        'guuu',
        style: TextStyle(  decoration: isChecked ? TextDecoration.lineThrough : null),
      ),
      trailing: TaskCheckbox(
        checkboxState: isChecked,toggleCheckboxState: checkboxCallback,
      ),
    );
  }
}

class TaskCheckbox extends StatelessWidget {
  final bool checkboxState;
  final Function toggleCheckboxState;

  const TaskCheckbox({Key? key, required this.checkboxState, required this.toggleCheckboxState}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Checkbox(
      value: checkboxState,
      activeColor: Colors.lightBlueAccent,
      onChanged: toggleCheckboxState
    );
  }
}