【发布时间】:2021-07-04 07:43:12
【问题描述】:
:25:23: 错误:位置参数太少:需要 1,给定 0。 BottomTabBtn(imagePath: "assets/images/tab_home.png"), ^ lib/widgets/bottom_tabs.dart:37:3:上下文:找到了这个候选人,但参数不匹配。 BottomTabBtn(this.imagePath); ^^^^^^^^^^^^^ lib/widgets/bottom_tabs.dart:26:23:错误:位置参数太少:需要 1,给定 0。 BottomTabBtn(imagePath: "assets/images/tab_search.png"), ^ lib/widgets/bottom_tabs.dart:37:3:上下文:找到了这个候选人,但参数不匹配。 BottomTabBtn(this.imagePath); ^^^^^^^^^^^^^ lib/widgets/bottom_tabs.dart:27:23:错误:位置参数太少:需要 1,给定 0。 BottomTabBtn(imagePath: "assets/images/tab_saved.png"), ^ lib/widgets/bottom_tabs.dart:37:3:上下文:找到了这个候选人,但参数不匹配。 BottomTabBtn(this.imagePath); ^^^^^^^^^^^^^ lib/widgets/bottom_tabs.dart:28:23:错误:位置参数太少:需要 1,给定 0。 BottomTabBtn(imagePath: "assets/images/tab_logout.png"), ^ lib/widgets/bottom_tabs.dart:37:3:上下文:找到了这个候选人,但参数不匹配。 BottomTabBtn(this.imagePath); ^^^^^^^^^^^^^
FAILURE:构建失败并出现异常。
-
在哪里: 脚本 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' 行:1035
-
出了什么问题: 任务 ':app:compileFlutterBuildDebug' 执行失败。
Process 'command 'C:\src\flutter\bin\flutter.bat'' 以非零退出值 1 结束
-
尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
-
通过https://help.gradle.org获得更多帮助
在 56 秒内构建失败 异常:Gradle 任务 assembleDebug 失败,退出代码为 1
这是我的代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class BottomTabs extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0)
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
spreadRadius: 1.0,
blurRadius: 30.0,
)
]
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
BottomTabBtn(imagePath: "assets/images/tab_home.png"),
BottomTabBtn(imagePath: "assets/images/tab_search.png"),
BottomTabBtn(imagePath: "assets/images/tab_saved.png"),
BottomTabBtn(imagePath: "assets/images/tab_logout.png"),
],
),
);
}
}
class BottomTabBtn extends StatelessWidget {
final String? imagePath;
BottomTabBtn(this.imagePath);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(
vertical: 22.0,
horizontal: 16.0
),
child: Image(
image: AssetImage(
imagePath ?? "assets/images/tab_home.png"
),
width: 22.0,
height: 22.0,
),
);
}
}
【问题讨论】:
-
你在构造函数中给出了命名参数,所以要么删除命名参数,要么像这样创建构造函数,以便它可以接受命名参数:
BottomTabBtn({this.imagePath});
标签: android flutter dart flutter-layout flutter-animation