flutter - 颤振/飞镖上的列错误所需的参数
问题描述
错误提示需要 1 个必需参数,但找到了 0 个。在每个颤振项目中,Column 都会给出错误。在 VS 代码上打开了一个新的颤振项目,但仍然给出相同的错误。
已更新 dart,在 VS 上卸载了颤振和飞镖并再次安装,我的颤振医生运行良好。
进口package:flutter/material.dart
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
child: Column(
mainAxisAlignment: MainAxisAlignment.center ,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
应有 1 个必需参数,但找到了 0 个。尝试添加额外的必需参数。
解决方案
这是完整的代码,用我的替换你的。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
推荐阅读
- javascript - 从通用类型对象中获取属性值并将其转换为 Typescript?
- wordpress - Elementor:以管理员身份登录时,对页面所做的更改不会出现在实时页面上
- django - 增量值独立于 Django 模板中的循环
- git - Azure DevOps Git 阻止在同一项目上工作
- maven - 如何在 jenkins 管道中更新 pom.xml 而无需开发人员更改他的 pom.xml?
- android - 如何在 Android 中使用 ContentResolver 删除自定义文件夹中的图像/视频?
- docker - dockerignore 即使写得正确也不起作用
- java - 引脚视图光标形状不变
- django - 为什么 django 没有将用户添加到我的表中(我正在使用 postgres)?
- java - Spring Cloud Gateway - 获取 405 方法不允许