Consider the following code for a PatientNameDisplay widget in a hospital app made with Flutter:

class PatientNameDisplay extends StatefulWidget {
  final String patientName;
  final bool isAlive;
  PatientNameDisplay({this.patientName, this.isAlive});

  State<PatientNameDisplay> createState() => _PatientNameDisplayState();

class _PatientNameDisplayState extends State<PatientNameDisplay> {
  Widget build(BuildContext context) {
    return Text(
      (widget.patientName ?? "John Doe"),
      style: TextStyle(color: widget.isAlive ? :,

The PatientNameDisplay widget defined above is used to display a patient's name. It has the following requirements:

  • The widget might receive patientName as null in the case of anonymous patients.
  • The widget will always receive the patient's status in the isAlive field.

Considering the requirements and the code above, what needs to be done to migrate the code to have sound null safety?

(Select all acceptable answers.)

Add null assertion operator(!) to widget.patientName.
Add null assertion operator(!) to widget.isAlive.
Make patientName variable a nullable type by adding ? after String.
Add the required keyword for the constructor's named parameter isAlive.
Add the required keyword for the constructor's named parameter patientName.
Make isAlive variable a nullable type by adding ? after bool.

Flutter Null Safety New Public


Would you like to see our other questions?

We have 1000+ premium hand-crafted questions for 160+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library
Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.

Contact Private Concierge

Would you like to see our tests? The following tests contain Flutter related questions:
On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...

Dashboard Start Trial Sign In Home Tour Tests Questions Pricing