這是從其父類接收標識要修改的框的索引資料的子類
class InformationPatient extends StatefulWidget {
final Patients patients;
final int index;
const InformationPatient(this.patients, this.index, {Key? key})
: super(key: key);
@override
State<InformationPatient> createState() => _InformationPatientState();
}
class _InformationPatientState extends State<InformationPatient> {
final int indexitem = 0;
late Box<Patients> boxPatient;
@override
void initState() {
super.initState();
boxPatient = Hive.box('Patient');
}
void _addNote(String newtitle, String newnote, String newconclusion) {
final newNOTE = Patients(
listOfNotes: [
ListNote(title: newtitle, note: newnote, conclusion: newconclusion)
],
);
boxPatient.put(indexitem, newNOTE);
Navigator.of(context).pop();
}
這種方式有效,但我沒有父母的索引,我把它給他
final int indexitem = 0; <--- Works perfectly with my function patientbox.put() it receives the index
boxPatient.put(indexitem, newNOTE);
我想為 indexbox 提供 index 的值,但我不知道該怎么做,或者是否有其他方法
final int indexitem = ??? <---- add the value of index
boxPatient.put(indexitem, newNOTE);
顯然我不能在函式 boxPatient.put() 中直接使用索引
非常感謝您的幫助
uj5u.com熱心網友回復:
要從狀態內部的小部件中讀取變數,您可以簡單地參考widget.<variable>. 所以在你的例子中
boxPatient.put(widget.index, newNOTE);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/530392.html
標籤:扑镖
