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'),
)
],
),
);
}
}
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'),
)
],
),
);
}
}