Dart 在已发布的颤振/飞镖包中重构参数名称时,如何保持向后兼容性?

Dart 在已发布的颤振/飞镖包中重构参数名称时,如何保持向后兼容性?,dart,flutter,alias,flutter-packages,Dart,Flutter,Alias,Flutter Packages,我正在为我的第一个开源flutter库做贡献,并且不得不更改一些变量名以使项目连贯一致 该库的所有者指出,重构后的参数将破坏从以前版本更新的应用程序。 他让我使用alias并将旧变量设置为不推荐的,以便开发人员可以将其更改为下一个主要realese 我在谷歌上做过一些搜索,但找不到如何以专业的方式做这类事情的教程。 实际上我根本找不到关于别名的信息 有人能帮我帮助社区吗 编辑:构造函数之前和之后 之前: CarouselSlider({ @required this.items, t

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

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

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;

看到具体的代码示例会容易得多。完成,希望有帮助。谢谢,非常感谢!除非有人在24小时内对此提出异议,否则我会将其标记为正确答案。