flutter - 如何获得扩展方法来更改 Dart 中的原始对象?
问题描述
我有bounds
。应使用新的 LatLng 扩展边界。
var bounds = LatLngBounds();
for (var latlng in _list) bounds.extend(latlng);
我想实现这个扩展:
extension LatLngBoundsExtend on LatLngBounds {
extend(LatLng _latLng){
//I want to change the object which this method is called from
this = LatLngBounds(southwest: /* some magic code*/, northeast: /* some magic code*/ );
}
}
解决方案
如果原始对象的属性不是最终的,则可以更改原始对象。和的情况并非如此LatLngBounds.southwest
LatLngBounds.northeast
。
推荐阅读
- sass - Webpack 将 sass 编译成 css 文件问题
- ibm-watson - 如何将 Watson Assistant“listLogs”API 函数用于版本化工作区?
- python - 为每个用户添加计数注释,然后按最近发生的日期排序
- javascript - chart.js zeroLineColor 无法按预期工作
- azure - Azure 共享访问签名创建
- git - 无法从原始远程 (github) 同步标签
- python - 可以在 Django 模板的下面代码中添加斜杠吗?
- sql - 在 postgres 中将额外的零附加到小数点后两位
- lisp - 在 Maxima 中编写用于评估逻辑的包
- mysql - mysql中的位数据类型