Инициализация поля

Home   »   Инициализация поля

void main() {
  final bar = Bar();

  print(bar.model.value);
  bar.model.value = "bleec";
  print(bar.model.value);
  bar.model = SomeModel();
  print(bar.model.value);

}

abstract class Model {
  abstract T? value;
}

class SomeModel extends Model {
  SomeModel() {
    print('SomeModel');
    value = 'value';
  }

  @override
  String? value;
}

abstract class Foo {
  abstract  Model model;
}

class Bar extends Foo {
  @override
  Model model = SomeModel();
}

Leave a Reply

Your email address will not be published.