gpt4 book ai didi

dart - 在已发布的 Flutter/Dart 包中重构参数名称时如何保持向后兼容性?

转载 作者:IT王子 更新时间:2023-10-29 06:51:12 25 4
gpt4 key购买 nike

我正在为我的第一个开源 flutter 库做贡献,必须更改一些变量名称以使项目连贯。

库所有者指出重构的参数会破坏从以前版本更新的应用程序。他让我使用别名并将旧变量设置为弃用,以便开发人员可以将其更改为下一个主要版本。

我已经进行了一些谷歌搜索,但找不到有关如何以专业方式执行此类操作的教程。我实际上根本找不到有关别名的信息。

有人可以帮助我帮助社区吗?

编辑:构造函数前后

之前:

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;

关于dart - 在已发布的 Flutter/Dart 包中重构参数名称时如何保持向后兼容性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54759908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com