Reputation: 11
I try to solve Incorrect use of ParentDataWidget
Exception caught by widgets library:
Incorrect use of ParentDataWidget.
import 'package:flutter/material.dart';
import 'package:user_profile_example/data.dart';
import 'package:user_profile_example/widget/cookbook_item.dart';
class bookmarked_recipes extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
// Design a clickable container which has a row of icon and text.
InkWell(
child: Align(
// Align them on the left of the screen.
alignment: Alignment.centerLeft,
child: Container(
margin: EdgeInsets.all(15),
child: Row(
children: [
Icon(Icons.add),
Text("Add new cookbook", style: TextStyle(fontSize: 16)),
],
)),
),
onTap: () {},
),
// make the rest of the screen for the gridview items.
Expanded(
child: GridView.count(
crossAxisCount: 2, // 2 items in each row
padding: EdgeInsets.all(25),
// map all available cookbooks and list them in Gridviwe.
children: Cookbook_Data.map((c) => cookbook_item(
key,
c.id,
c.cookbookName,
c.imageURLCookbook,
)).toList(),
),
),
]),
);
}
}
Upvotes: 0
Views: 98
Reputation: 11
Ok This is the class of cook_book_item I don't understand where is the problem I should fix the error as soon as posible
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class cookbook_item extends StatelessWidget {
final String id;
final String cookbookName;
final String imageURLCookbook;
// final VoidCallback onClicked;
const cookbook_item(
Key? key,
this.id,
this.cookbookName,
this.imageURLCookbook,
);
void selectCookbook() {}
@override
Widget build(BuildContext context) {
final String image = imageURLCookbook;
// this section will return one item of Grid Items that in bookmarked recipes page.
return InkWell(
onTap: () {},
child: Stack(
children: [
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(imageURLCookbook),
),
),
Container(
padding: EdgeInsets.symmetric(vertical: 10),
color: Color(0xff9C635614),
child: Text(cookbookName,
style: TextStyle(fontSize: 15, color: Colors.white)),
),
],
),
);
}
}
Upvotes: 0
Reputation: 14885
Try below code hope its helpful to you. try to Just remove your Expanded
Widget
change my children to your children , refer GridView.count()
here
Column(
children: [
InkWell(
child: Align(
// Align them on the left of the screen.
alignment: Alignment.centerLeft,
child: Container(
margin: EdgeInsets.all(15),
child: Row(
children: [
Icon(Icons.add),
Text(
"Add new cookbook",
style: TextStyle(fontSize: 16),
),
],
),
),
),
onTap: () {},
),
// make the rest of the sceen for the gridview items.
GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 2, // 2 items in each row
padding: EdgeInsets.all(25),
// map all available cookbooks and list them in Gridviwe.
children: List.generate(
10,
(index) {
return Center(
child: Text(
'Item $index',
style: Theme.of(context).textTheme.headline5,
),
);
},
),
),
],
),
Upvotes: 1
Reputation: 1216
GridView
will take up all the space there is just like what an Expanded
widget does. So, the Expanded
is redundant and also the reason for "Incorrect use of ParentDataWidget". So try removing the Expanded
widget.
Upvotes: 0