flutter - 如何修复 Flutter MaterialApp(not_enough_required_arguments)?
问题描述
当返回 MaterialApp 颤振显示错误如下“错误:1 个必需的参数(s)预期,但 0 找到。(not_enough_required_arguments at [demo] lib/main.dart:9)”这是截图
const _categoryName = "Cake";
const _categoryIcon = Icons.cake;
const _categoryColor = Colors.green;
import 'package:solution_02_category_widget/category.dart';
void main() {
runApp(UnitConverterApp());
}
class UnitConverterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Unit Converter',
home: Scaffold(
backgroundColor: Colors.green[100],
body: Center(
child: Category(
name: _categoryName,
color: _categoryColor,
iconLocation: _categoryIcon,
),
),
),
);
}
}
解决方案
您应该将 title 参数包装在 AppBar Widget 下。您可以反过来将 appBar 参数包装在 Scaffold 中。脚手架就像一个空白页面,为您的应用程序提供白色背景。下面是一个示例代码实现:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// debugShowMaterialGrid: true,
theme: ThemeData(
brightness: Brightness .light,
accentColor: Colors.deepPurple,
primarySwatch: Colors.deepOrange),
home: Scaffold(
appBar: AppBar(
title: Text('Some text'),
),
),
);
}
}
推荐阅读
- go - 频道有一个奇怪的行为,为什么会阻塞?
- atom-editor - 如何更改 Atom 中用于 ERB 的语法?
- android - Android - 推送通知:FirebaseMessagingService 类的用途?
- recaptcha - recaptcha v2 没有获得“成功”
- c# - Monogame C#:将图像分配给 2D 数组?
- macos - 如何通过在 Mac App Store 上购买旧版本来判断某个应用是否已经购买(许可)?
- sql-server - Power BI 处理 16gb CSV 文件
- multithreading - 如何将协程直接分派到 JVM 上的主线程?
- vba - 无论字符串中的哪个位置都摆脱空格
- c++ - Eclipse C++ 调试器不会在断点处停止并在调试开始后立即终止