1

我正在为我的第一个开源颤振库做出贡献,并且不得不更改一些变量名称以使项目连贯。

库所有者指出重构的参数将破坏从以前版本更新的人的应用程序。他让我使用 alias 并将旧变量设置为 deprecated,以便开发人员可以将其更改为下一个主要的 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
4

1 回答 1

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;
于 2019-02-19T07:47:43.427 回答