Estoy recibiendo este error en mi código
======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building TaskCheckbox(dirty):
Closure call with mismatched arguments: function '_TaskTileState.checkboxCallback'
Receiver: Closure: (bool) => void from Function 'checkboxCallback':.
Tried calling: _TaskTileState.checkboxCallback()
Found: _TaskTileState.checkboxCallback(bool) => void
The relevant error-causing widget was:
TaskCheckbox TaskCheckbox:file:///F:/Code/Flutter/todoey_flutter/lib/widgets/task_tile.dart:28:17
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
#1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:106:9)
The relevant error-causing widget was:
TaskCheckbox TaskCheckbox:file:///F:/Code/Flutter/todoey_flutter/lib/widgets/task_tile.dart:28:17
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
#1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:106:9)
Aquí está mi código que a través de este error
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
State<TaskTile> createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked = false;
void checkboxCallback(bool checkboxState) {
setState(() {
isChecked = checkboxState;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
'This is task',
style: TextStyle(
decoration: isChecked? TextDecoration.lineThrough: null,
),
),
trailing: TaskCheckbox(isChecked, checkboxCallback),
);
}
}
class TaskCheckbox extends StatelessWidget {
final bool checkboxState;
final Function toggleCheckboxState;
TaskCheckbox(this.checkboxState, this.toggleCheckboxState);
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.lightBlueAccent,
value: checkboxState,
onChanged: toggleCheckboxState(),
);
}
}
Estoy tratando de crear un estado global para intercambiar datos entre dos clases diferentes y cambiar el estado en la pantalla.
- esta es una aplicación de gestión de tareas en la que obtengo los datos de una variable estática. Quiero intercambiar valores booleanos entre dos clases y mostrar la lista de tareas de acuerdo con ese valor booleano.*
¿Puede alguien ayudarme con esto?
Solución del problema
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
State<TaskTile> createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked=false;
void CheckBoxCallback(bool? checkboxstate){
setState(() {
isChecked = checkboxstate!;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text('baking today',
style: TextStyle(
decoration: isChecked?TextDecoration.lineThrough:null),),
trailing: TaskCheckBox(
checkboxstate: isChecked,
togglecheckboxstate: CheckBoxCallback,
),
);
}
}
class TaskCheckBox extends StatelessWidget {
final bool checkboxstate;
final Function(bool?)? togglecheckboxstate; // Here is where to make changes, observe the "bool?" i added.
TaskCheckBox({required this.checkboxstate,required this.togglecheckboxstate});
@override
Widget build(BuildContext context) {
return Checkbox(
value: checkboxstate,
onChanged:togglecheckboxstate, // and here too on your code
);
}
}
No hay comentarios:
Publicar un comentario