flutter - Flutter 找不到小部件属性:'child' 未定义
问题描述
因为很少有人发布一些错误的解决方案(这不是坏主意),我回复了他们然后他们删除了他们的帖子。我通过适度获得了标志......所以我在这里发布每个答案。
1/ 我正在尝试使用 child 和 onPressed 属性制作一个简单的 ElevatedButton。
2/ 我尝试遵循此处提供的文档:https ://api.flutter.dev/flutter/material/ElevatedButton-class.html
我也使用了示例,但每次我得到相同的错误:“未定义命名参数'child'。” ('onPressed' 也没有定义......')
3/ 自动完成属性的图片: ElevatedButton Properties
使用的 Flutter 版本: Flutter 2.0.4 • 通道稳定 • https://github.com/flutter/flutter.git 框架 • 修订 b1395592de(10 天前) • 2021-04-01 14:25:01 -0700 引擎 • 修订2dce47073a 工具 • Dart 2.12.2
这是完整的代码,我可以再次运行和调试,但我的 Visual Studio 编译器中仍然有错误,正如您在屏幕截图中看到的那样......我不明白为什么。
我按 F5 运行模拟器,然后我使用“fultter run”启动我的应用程序。
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: Home(),
));
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("HelloWorld"),
centerTitle: true,
backgroundColor: Colors.red[600],
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("Hello World"),
ElevatedButton.icon(
label: Text("Click"),
icon: Icon(Icons.airplanemode_active),
onPressed: () {},
),
Container(
color: Colors.lightBlue,
padding: EdgeInsets.all(20.0),
child: Text("container"),
),
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Colors.red[600],
onPressed: () {},
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 45,
width: 100,
),
color: Colors.pink,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
}
class TestFul extends StatefulWidget {
@override
_TestFulState createState() => _TestFulState();
}
class _TestFulState extends State<TestFul> {
@override
Widget build(BuildContext context) {
return Container();
}
}
感谢大家快速回复我的帖子。
令人惊讶的是,我可以使用我的模拟器调试和运行我的代码。但我仍然有错误,你可以在图片链接中看到: 问题
我试图清理/缓存/重新启动等...但没有任何改变。当然,我正在导入 material.dart 是否可能是 Flutter 2.0.4 版本的原因?
PS:我正在使用 Visual Studio Code 进行编码。我不认为不看错误的编码是一个好习惯^^'。
解决方案
推荐阅读
- javascript - 如何将从 useEffect 中获取的 initialValue 放在 textField 中?
- wpf - 如何在 WPF DataGrid 中实现行
- build - 我可以为所有平台交叉构建电子锻造应用程序吗?
- javascript - 如何以多个值获取 request.GET.get('variable')
- python - python pandas中的日期和时间转换
- javascript - 在 UI 中输入值和示例数据时使用 JSONata 获取动态输出
- dns - www.hisdomain.com 指向 subA.mydomain.com
- reactjs - 用 typescript 定义 react redux 状态
- powerbi - 将excel公式转换为DAX / M
- javascript - 如何在 p5.js 中打开相机并检测鼻子