启动应用程序时出现此错误。我理解错误,但我不知道如何找到错误。请帮我纠正错误。
class NoteCardWidget extends StatefulWidget {
final NotedB note;
const NoteCardWidget({
Key? key,
required this.note,
}) : super(key: key);
@override
State<NoteCardWidget> createState() => _NoteCardWidgetState();
}
class _NoteCardWidgetState extends State<NoteCardWidget> {
final controllerKey = GlobalKey<NoteDetailsState>();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: const Color(0xFFF4E0F7),
appBar: AppBar(
iconTheme: const IconThemeData(color: Colors.black),
backgroundColor: Colors.transparent,
actions: [
IconButton(
key: controllerKey,
onPressed: () async {
setState(() {
widget.note.title =
controllerKey.currentState!.titleController.text;
widget.note.description =
controllerKey.currentState!.descController.text;
});
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => NoteDetails(
noteId: widget.note.id,
),
));
},
icon: const Icon(
Icons.edit,
)),
TextButton(
onPressed: () async {
await Databahelper.instance.deleteNote(widget.note.id!);
Navigator.pop(context);
},
child: const Icon(
Icons.delete,
color: Colors.black,
)),
],
elevation: 0,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.arrow_back)),
),
//**********************************AppBar*********************************** */
body: SingleChildScrollView(
child: Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
children: [
const SizedBox(
height: 25,
),
Text(widget.note.title,
style: const TextStyle(
fontSize: 30, fontWeight: FontWeight.bold)),
const SizedBox(height: 15),
Text(
widget.note.description,
style: const TextStyle(
fontFamily: 'fonts/Schyler-Regular.ttf',
fontSize: 24,
),
),
],
),
)),
),
),
);
}
}
当我删除 setState() 方法中的请求时,我不再有错误,但我不知道通过什么其他方式访问这些变量。有人有建议吗?