如何在一个包中处理Flutter SDK的突破性更改



https://flutter.dev/docs/release/breaking-changes/parent-data-widget-generic-type

我最近注意到ParentDataWidget正在计划进行这种突破性的更改。

如果ParentDataWidget的通用类型是RenderObjectWidget,那么在Stable分支的当前最新v1.12.13+修补程序.8中应该是这样,Flutter v1.13.7和更新版本对此表示不满。在中断更改之前和之后,是否有支持这两个版本的变通方法?


v1.12.13+修补程序.8

class FrogSize extends ParentDataWidget<FrogJar> {
...
}

v1.13.7 之后

class FrogSize extends ParentDataWidget<FrogJarParentData> {
...
@override
Type get debugTypicalAncestorWidgetClass => FrogJar;
}

试试这个。我使用dev分支编译了以下代码,但希望也适用于您的特定版本。

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'stack.dart';
class CircleContainer extends ParentDataWidget<CircleStackParentData> { //<== Changed CircleStack to  CircleStackParentData
const CircleContainer({
Key key,
this.width,
this.height,
@required Widget child,
this.degree,
this.distance = 0.0,
this.rotate = 0.0,
this.align = Alignment.topLeft,
})  : assert(width == null || width > 0.0),
assert(height == null || height > 0.0),
assert(child != null),
assert(distance != null),
assert(rotate != null),
assert(align != null),
super(key: key, child: child);
final double width;
final double height;
final double distance;
final double degree;
final double rotate;
final Alignment align;
@override
void applyParentData(RenderObject renderObject) {
assert(renderObject.parentData is StackParentData);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('width', width, defaultValue: null));
properties.add(DoubleProperty('height', height, defaultValue: null));
}
static CircleContainer of(BuildContext context) {
return context.findAncestorWidgetOfExactType<CircleContainer>();
}
@override
Type get debugTypicalAncestorWidgetClass => CircleStack; //<== New added line
}
//New Added Class
class CircleStackParentData extends ParentData {
double width;
double height;
double distance;
double degree;
double rotate;
Alignment align;
}

最新更新