1
answer
1
watching
241
views

My Flutter code got the error message - No MediaQuery widget ancestor found. 

You responded back to do this - 

return MediaQuery(

    data: MediaQueryData(),

    child: MaterialApp(

    home: Scaffold(

    body: SizedBox(

    height: MediaQuery.of(context).size.height,

    child: const Dashboard(),

   ),

)

So where do I put this in my code listed below?

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

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

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: 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 and 3 others

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