1
answer
1
watching
233
views

Using Flutter Version 3.3.6 - 

My code below - I got this message which I don't understand

No MediaQuery widget ancestor found.
Scaffold widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was:
  Scaffold
The ownership chain for the affected widget is: "Scaffold ← FoodList ← [root]"
No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.

 

import 'package:flutter/material.dart';
void main() {runApp(const FoodList());}

class FoodList extends StatelessWidget {
const FoodList({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Food List"),
),
body: ListView(
children: const <Widget>[
ListTile(
title: Text("Food Item 1"),
trailing: Checkbox(value: false, onChanged: null),
),
ListTile(
title: Text("Food Item 2"),
trailing: Checkbox(value: false, onChanged: null),
),
ListTile(
title: Text("Food Item 3"),
trailing: Checkbox(value: false, onChanged: null),
),
ListTile(
title: Text("Food Item 4"),
trailing: Checkbox(value: false, onChanged: null),
),
ListTile(
title: Text("Food Item 5"),
trailing: Checkbox(value: false, onChanged: null),
),
ElevatedButton(
onPressed: null,
child: Text('Submit'),
)
],
),
);
}
}

For unlimited access to Homework Help, a Homework+ subscription is required.

Avatar image
Liked by dragon2020

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in

Weekly leaderboard

Start filling in the gaps now
Log in