【发布时间】:2019-08-04 07:19:13
【问题描述】:
我正在学习 Udacity 的 Flutter 课程。 对于一些任务,我正在学习如何创建小部件。 来自 C++/Python,我根本无法理解此类构造函数的语法。
所以我的 main.dart 在中心小部件内包含一个类别小部件(我正在构建的那个)。我从 main.dart 文件传递了 3 个参数,但我不明白
const Category({...}) : ... ;
部分正在做。
这是我的 category.dart 的样子:
import 'package:flutter/material.dart';
class Category extends StatelessWidget {
final String name;
final ColorSwatch color;
final IconData iconLocation;
const Category({
Key key,
@required this.name,
@required this.color,
@required this.iconLocation,
}) : assert(name != null),
assert(color != null),
assert(iconLocation != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 100.0,
padding: EdgeInsets.all(8.0),
child: InkWell(
borderRadius: BorderRadius.circular(25.0),
splashColor: color,
onTap: () {
print('i am cool');
},
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.all(16.0),
child: Icon(
iconLocation,
size: 60.0,
),
),
Text(
'Length',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24.0,
),
),
],
),
),
);
}
}
【问题讨论】: