I am creating a todo app that contains TaskList and Task Tiles and by creating check boxes of task lists and using call back functions I got 3 types of errors.
- RenderBox was not laid out 2) Failed assertion: line 1930 pos 12: 'hasSize' 3)Null check operator used on a null value
TaskList class code:
import 'package:flutter/material.dart';
import 'package:todoey_flutter/widgets/TaskTile.dart';
class TaskList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
TaskTile(),
TaskTile(),
],
);
}
}
TaskTile code that contains checkbox and callback:
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
_TaskTileState createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked= false;
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
'This is my task.',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null,
),),
trailing: TaskCheckBox(isChecked, (bool checkboxState) {
setState(() {
isChecked = checkboxState;
});
},
),
);
}
}
class TaskCheckBox extends StatelessWidget {
TaskCheckBox (this.checkboxState, this.toggleCheckBoxState);
final bool checkboxState;
final Function toggleCheckBoxState;
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.blueAccent,
value: checkboxState,
onChanged: toggleCheckBoxState(),
);
}
}
Aucun commentaire:
Enregistrer un commentaire