假设我从文档中有这个类:
abstract class GeographicArea {
int get population;
String get name;
}
@freezed
class Example with _$Example {
const factory Example.person(String name, int age) = Person;
@Implements<GeographicArea>()
const factory Example.city(String name, int population) = City;
}
我有一个Example类型的对象,我如何检查该示例是否实现了Geographicarea并将其复制为Interfacspecific属性?
var example = Example.city();
//How to check if this instance implements GeographicArea and call copyWith with a GeographicArea specific parameter?
example = example.copyWith(population: 20000);
1条答案
按热度按时间bsxbgnwa1#
你可以用'is'关键字来检查它