-1

I try to use @frezzed tech. in my flutter ptoject for working with DB-firbase. enter image description here

How I can acess to class vars for manipulating?

import 'package:freezed_annotation/freezed_annotation.dart';
part 'Person.freezed.dart';

@freezed
class Person with _$Person {
  const Person._(); // Added constructor
  const factory Person(String name, {int? age}) = _Person;
  const factory Person.manager(String? ttt) = Manager;
  
  void method() {
    print('hello world');
    Person p = Person("name");
    p.  
  }
}
julemand101
  • 28,470
  • 5
  • 52
  • 48

1 Answers1

0
@freezed
class Person with _$Person {
  factory Person({ String? name, int? age }) = _Person;
}

Which then allows you to write:

var person = Person(name: 'Remi', age: 24);
print(person.name); // Remi
print(person.age); // 24

source - freezed docs

Mohit Kushwaha
  • 1,003
  • 1
  • 10
  • 15
  • Yes. But i have error "The getter 'name' isn't defined for the type 'Person'. Try importing the library that defines 'name', correcting the name to the name of an existing getter, or defining a getter or field named 'name'." – Yerbol Kistaubayev Jul 16 '21 at 16:41
  • try, refer to this - [article](https://developer.school/how-to-use-freezed-with-flutter/) freezed implementation - [repo](https://github.com/ThiagoEvoa/dartfn/tree/5c03b19f529ac8ddd0306a4418f6bb99f4213115/dart_backend/lib/model) – Mohit Kushwaha Jul 17 '21 at 05:29