flutter - 如何在简单的代码中修复 ParentDataWidget 的错误使用
问题描述
我尝试解决不正确使用 ParentDataWidget
小部件库捕获的异常:
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(),
),
),
]),
);
}
}
解决方案
试试下面的代码希望它对你有帮助。尝试只需删除您的Expanded
小部件将我的孩子更改为您的孩子,请参阅GridView.count()
此处
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,
),
);
},
),
),
],
),
推荐阅读
- excel - 在其他工作表中查找日期
- java - 无法为接口 android.app.IAlarmManager 调用无参数构造函数
- google-tag-manager - 验证后的 Google 跟踪代码管理器触发器 - 页面路径或页面 URL 星标不起作用
- jsp - 在 EL 中使用 getter 而不是字段名更安全吗?
- java - 如何处理数组类型的Java默认构造函数参数?(没有静态工厂方法或构建器模式)
- angular - 如何在 Angular 8.2.14 中正确使用 ngStyle?
- python - Python - 如何通过 for 循环组合数据帧?
- python - 理解 Python 中的访问器和修改器
- java - 如何将日期字符串转换为 joda DateTime?
- swift - 如何在swift中向textview文本添加两种不同的字体大小