CodeSampleX

Exemple

equatable 2.1.0: Verify that Equatable does not automatically stringify properties in toString() unless explicitly enabled

Échantillon vérifié pour pub equatable 2.1.0: Verify that Equatable does not automatically stringify properties in toString() unless explicitly enabled. Le…

sha256:bec4ea595f73e58cfacf6eb4297d3478d35d6f1994148f087b6ebcf9904d4aec

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
2
Environnement déclaré dart linux x64 dart dart pub

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
dart 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-17
dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-18

Cas

HOW
Objectif
Verify that Equatable does not automatically stringify properties in toString() unless explicitly enabled
Paquets
Symboles
  • Equatable
  • stringify
Environnement
dart
Créé
2026-08-17T02:07:29Z

Contrat

  1. if (User('alice').toString() != 'User') throw 'toString defaults to just the class name, not the formatted props';

Fichiers

  • NOTES.md
  • csx.json
  • pubspec.lock
  • pubspec.yaml
  • test/contract.dart
  • test_stringify.dart

Télécharger l’artefact source (tar.gz)

Code source

NOTES.md
When overriding `props` in a class extending `Equatable`, it is common to assume that `toString()` will automatically return a formatted string of the object's properties (e.g. `User(alice)`). 

However, by default, `toString()` only returns the class name. To include the properties, one must explicitly override `bool get stringify => true;` or configure `EquatableConfig.stringify = true;` globally.

The `search_known_solution` lookup yielded two different samples for this library: one covering `runtimeType` checks preventing equality for generics, and another covering basic value equality. This sample demonstrates the default `stringify` behavior instead.
csx.json
{"case":{"believed":"A class extending Equatable automatically formats its fields in toString() output by iterating over its overridden props.","caseId":"case:sha256:a17995751f6d968cc8e0b1879e40ef1da8bc04cece9e78ef2c23a1a5742a8c9d","contract":["if (User('alice').toString() != 'User') throw 'toString defaults to just the class name, not the formatted props';"],"goal":"Verify that Equatable does not automatically stringify properties in toString() unless explicitly enabled","kind":"HOW","packages":["pkg:pub/equatable@2.1.0"],"schemaVersion":1,"symbols":["Equatable","stringify"]},"contractCommand":["dart","test/contract.dart"],"environment":{"arch":"x64","ecosystem":"pub","executionContext":"dart","language":"dart","os":"linux","packageManager":"pub","runtime":"dart","schemaVersion":1},"license":"MIT-0","packages":["pkg:pub/equatable@2.1.0"],"schemaVersion":1,"symbols":["Equatable","stringify"],"verifierAdapter":"pub@1"}
pubspec.lock
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  collection:
    dependency: transitive
    description:
      name: collection
      sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
      url: "https://pub.dev"
    source: hosted
    version: "1.19.1"
  equatable:
    dependency: "direct main"
    description:
      name: equatable
      sha256: "3bce007a596ff8b3119c45d68aaef631272537c03d30e5d4534dd24bf4c5eaa2"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.0"
  meta:
    dependency: transitive
    description:
      name: meta
      sha256: "307249ce4ff29d58a18e97f6345f539382eb9c9c29ecda628900f31de0443dd9"
      url: "https://pub.dev"
    source: hosted
    version: "1.19.0"
sdks:
  dart: ">=3.5.0 <4.0.0"
pubspec.yaml
name: sample
environment:
  sdk: '>=3.0.0 <4.0.0'
dependencies:
  equatable: ^2.1.0
test/contract.dart
import 'package:equatable/equatable.dart';

class User extends Equatable {
  final String name;
  const User(this.name);
  
  @override
  List<Object?> get props => [name];
}

void main() {
  if (User('alice').toString() != 'User') throw 'toString defaults to just the class name, not the formatted props';
}
test_stringify.dart
import 'package:equatable/equatable.dart';

class MyClass extends Equatable {
  final String id;
  const MyClass(this.id);
  
  @override
  List<Object?> get props => [id];
}

void main() {
  final obj = MyClass('abc');
  print('stringify is: ${obj.stringify}');
  print('toString returns: ${obj.toString()}');
}

Seeder d'origine

csx-seed