freezed_collection 0.0.1 copy "freezed_collection: ^0.0.1" to clipboard
freezed_collection: ^0.0.1 copied to clipboard

outdated

Extending dart:freezed to deep copyWith for collection.

example/freezed_collection_example.dart

import 'package:freezed_collection/freezed_collection.dart';

import 'dart:convert';

import 'assistant.dart';
import 'company.dart';
import 'director.dart';

void printT<T>(T company) => print(json.encode(company));

void main() {
  final company = Company(
      name: '1',
      director: Director(
          name: 'director1',
          assistants: FreezedList<Assistant>(
              [Assistant(age: 1, name: '1'), Assistant(age: 3, name: '3')])));

  final jsonString = json.encode(company);
  final restoredCompany = Company.fromJson(json.decode(jsonString));

  print(restoredCompany);

  Company? newCompany = company.copyWith.director.assistants.replaceFirst(
    Assistant(age: 2, name: '2'),
    (element) => element.age == 1,
  );

  Company? newCompany2 = newCompany.copyWith.director.assistants.replaceFirst(
    Assistant(age: 1, name: '1'),
    (element) => element.age == 2,
  );

  printT(company);
  printT(newCompany);
  printT(newCompany2);

  print('Is newCompany equal to company? ${newCompany == company}');
  print('Is newCompany equal to company? ${newCompany2 == company}');
}
3
likes
0
points
145
downloads

Publisher

verified publishermtbo.org

Weekly Downloads

Extending dart:freezed to deep copyWith for collection.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

freezed_annotation, json_annotation

More

Packages that depend on freezed_collection