我正在为我的第一个开源flutter库做贡献,并且不得不更改一些变量名以使项目连贯。
库所有者指出,重构的参数将破坏应用程序,使人们可以从以前的版本进行更新。 他要求我使用别名并将旧变量设置为不赞成使用,以便开发人员可以将其更改为下一个主要的Realese。
我已经进行了一些谷歌搜索,但是找不到有关如何以专业方式进行此类操作的教程。 我实际上根本找不到有关别名的信息。
有人可以帮助我帮助社区吗?
编辑:构造函数之前和之后
之前:
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
this.interval: const Duration(seconds: 4),
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
})
之后:
CarouselSlider({
@required
this.items,
this.height,
this.aspectRatio: 16/9,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.realPage: 10000,
this.reverse: false,
this.autoPlay: false,
this.autoPlayInterval: const Duration(seconds: 4),
this.autoPlayAnimationDuration: const Duration(milliseconds: 800),
this.autoPlayCurve: Curves.fastOutSlowIn,
this.enlargeCenterPage: false,
this.pauseAutoPlayOnTouch,
this.onPageChangedCallback,
})
重构名称:
interval --> autoPlayInterval
distortion --> enlargeCenterPage
autoPlayDuration --> autoPlayAnimationDuration
updateCallback --> onPageChanged
答案 0 :(得分:3)
interval
属性的示例
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
@Deprecated('use "autoplayInterval" instead')
Duration interval: const Duration(seconds: 4),
Duration autoplayInterval,
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
}) : assert(interval == null || autoplayInterval == null, 'Use either "interval" or "autoPlayInterval", but not both.'), autoplayInterval = autoplayInterval ?? interval;