1

I am facing this issue when I added a new property to the Freezed class for the first time in three months, and then run

flutter clean && flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs.

And I tried the answers on the following page, but it did not solve the problem.

flutter pub run build_runner build failed

flutter clean
flutter pub cache repair
flutter pub get
flutter pub run build_runner clean
flutter pub run build_runner build --delete-conflicting-outputs  

The following is my code before and after the change

//Before
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:~/models/item/item.dart';
part 'user.freezed.dart';
part 'user.g.dart';
part 'user_controller.dart';
@freezed
abstract class User with _$User {
  const factory User({
    @Default('') String name,
    @Default(35.6620) double latitude,
    @Default(139.7038) double longitude,
  }) = _User;
  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}

//After
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:~/models/item/item.dart';
part 'user.freezed.dart';
part 'user.g.dart';
part 'user_controller.dart';
@freezed
abstract class User with _$User {
  const factory User({
    @Default('') String name,
    @Default(35.6620) double latitude,
    @Default(139.7038) double longitude,
    int age,
    @Default('') String birthday,
    @Default('') String gender,
    @Default('') String imageURL,
    @Default('') String introduction,
    @Default('') String restaurant,
    @DateTimeConverter() DateTime updateAt,
    @DateTimeConverter() DateTime createAt,
    @Default('') String uri,
  }) = _User;
  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}
class DateTimeConverter implements JsonConverter<DateTime, Timestamp> {
  const DateTimeConverter();
  @override
  DateTime fromJson(Timestamp value) {
    return DateTime.parse(value.toDate().toString());
  }
  @override
  Timestamp toJson(DateTime value) => Timestamp.fromDate(value);
}

The following is the error message

Running "flutter pub get" in my_code...                        2,962ms
Failed to build build_runner:build_runner:
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:258:50: Error: The property 'displayString' is defined in multiple extensions for 'TargetKind' and neither is more specific.
 - 'TargetKind' is from 'package:meta/meta_meta.dart' ('../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart').
Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
        var kindNames = kinds.map((kind) => kind.displayString).toList()
                                                 ^^^^^^^^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:1950:14: Context: This is one of the extension members.
  String get displayString {
             ^^^^^^^^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart:91:14: Context: This is one of the extension members.
  String get displayString {
             ^^^^^^^^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:260:36: Error: The getter 'commaSeparatedWithOr' isn't defined for the class 'List<dynamic>'.
 - 'List' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'commaSeparatedWithOr'.
        var validKinds = kindNames.commaSeparatedWithOr;
                                   ^^^^^^^^^^^^^^^^^^^^
pub finished with exit code 1
Aspas
  • 11
  • 3

1 Answers1

0

I had the same problem. I deleted flutter SDK, and reinstalled the same version. And it started to work.

Im not using freezed tho, but one of my dependecies is using it.

If it helps, these are my dev_dependencies:

dev_dependencies:
  flutter_test:
    sdk: flutter

  json_serializable: ^3.5.0
  retrofit_generator: ^1.4.1+3
  hive_generator: ^1.0.0
  build_runner: ^1.11.5
paakjis
  • 369
  • 4
  • 16
  • 1
    Thank you for your help. "deleted flutter SDK, and reinstalled the same version" This worked for me!!! – Aspas Nov 11 '21 at 06:28