i get Error: The argument type 'Function?' can't be assigned to the parameter type 'void Function(bool?)?'. when i try to change toggle status of my checkbox how can i solve this problem?
itemCard
import 'package:flutter/material.dart';
class ItemCard extends StatelessWidget {
final String title;
final bool isDone;
final Function toggleStatus;//toggle status
const ItemCard(
{Key? key,
required this.title,
required this.isDone,
required this.toggleStatus})
: super(key: key);
@override
Widget build(BuildContext context) {
return Card(
elevation: 5,
shadowColor: Theme.of(context).primaryColor,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: ListTile(
title: Text(
title,
style: TextStyle(color: Colors.black),
),
trailing: Checkbox(
value: isDone,
activeColor: Colors.green,
onChanged: toggleStatus,//ERROR
),
));
}
}``
item
class Item {
final String title;
bool isDone;
Item({required this.title, this.isDone = false});
void toggleStatus() {
isDone = !isDone;
}
}
Aucun commentaire:
Enregistrer un commentaire