首页 > 解决方案 > 如何获得扩展方法来更改 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*/   );

  }
}

标签: flutterclassobjectdartextension-methods

解决方案


如果原始对象的属性不是最终的,则可以更改原始对象。的情况并非如此LatLngBounds.southwestLatLngBounds.northeast


推荐阅读