第一种写法(常见写法)
class NavigationIconView {
NavigationIconView ( Widget icon, Widget title, TickerProvider vsync) {
this.item = new BottomNavigationBarItem(
icon: icon,
title: title,
);
this.controller = new AnimationController(
duration: kThemeAnimationDuration,
vsync: vsync
);
}
}
第二种写法
class NavigationIconView {
NavigationIconView ({
Widget icon,
Widget title,
TickerProvider vsync,
}) :
item = new BottomNavigationBarItem(
icon: icon,
title: title,
),
controller = new AnimationController(
duration: kThemeAnimationDuration,
vsync: vsync
);
}
在调用上的区别:
第一种调用
_navigationViews = <NavigationIconView> [
new NavigationIconView(new Icon(Icons.assessment), new Text('首页'), this),
new NavigationIconView(new Icon(Icons.all_inclusive), new Text("想法"), this),
new NavigationIconView(new Icon(Icons.add_shopping_cart), new Text("市场"), this),
new NavigationIconView(new Icon(Icons.add_alert), new Text("通知"), this),
new NavigationIconView(new Icon(Icons.perm_identity), new Text("我的"), this),
];
第二种调用
_navigationViews = <NavigationIconView> [
new NavigationIconView(
icon: new Icon(Icons.assessment),
title: new Text('首页'),
vsync: this,
),
new NavigationIconView(
icon: new Icon(Icons.all_inclusive),
title: new Text("想法"),
vsync: this,
),
new NavigationIconView(
icon: new Icon(Icons.add_shopping_cart),
title: new Text("市场"),
vsync: this,
),
new NavigationIconView(
icon: new Icon(Icons.add_alert),
title: new Text("通知"),
vsync: this,
),
new NavigationIconView(
icon: new Icon(Icons.perm_identity),
title: new Text("我的"),
vsync: this,
),
];
对比可以看出,第二种写法在调用时,代码可读性更好,推荐第二种写法.
网友评论