'The getter 'sundayIsSelected' was called on null. Receiver: null Tried calling: sundayIsSelected
here I created a model, and try to use the model in the page, but I get an error:
The getter 'sundayIsSelected' was called on null.
Receiver: null
Tried calling: sundayIsSelected
I set the sundayIsSelected in AlarmClock default value is false, why in the TimePickerPage there is still null? thanks!
Here is model code:
class AlarmClock {
bool sundayIsSelected;
//I also tried followings:
//bool sundayIsSelected = false;
AlarmClock({
this.sundayIsSelected = false,
});
}
here is my page code.
class TimePickerPage extends StatefulWidget {
final AlarmClock alarmClock;
const TimePickerPage({Key key, this.alarmClock}) : super(key: key);
@override
_TimePickerPageState createState() => _TimePickerPageState();
}
class _TimePickerPageState extends State<TimePickerPage> {
bool sundayIsSelected;
@override
void initState() {
sundayIsSelected = widget.alarmClock.sundayIsSelected;
}
Widget build(BuildContext context) {
Text(sundayIsSelected),
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
