numen31337/copy_with_extension

Unable to use CopyWith when models are imported with namespace

rbresjer opened this issue · 2 comments

Describe the issue

I make use of FlutterFire Firebase Authentication. This package declares a model User which clashes with my own User model. Therefore I import Firebase Authentication namespaced: import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;. I have a model AuthenticationState which looks as follows:

@CopyWith()
class AuthenticationState {
  AuthenticationState({
    required this.user,
    this.firebaseUser,
  });

  final User user;
  final firebase_auth.User? firebaseUser;
}

CopyWith however doesn't take the namespace in account and sees both properties as User. I also tried defining a typedef typedef FirebaseUser = firebase_auth.User; and use that, but CopyWith then still types firebaseUser as User which resolves to my own User model.

Environment details

➜ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-x64, locale en-NL)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.66.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

➜ flutter --version
Flutter 2.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5464c5bac7 (3 days ago) • 2022-04-18 09:55:37 -0700
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2

Paste the package version.

dependencies:
  copy_with_extension: ^4.0.0
dev_dependencies:
  copy_with_extension_gen: ^4.0.1

To Reproduce

I think the issue is clear.

Expected behaviour

I think the issue is clear.

Additional context

Let me know what you need :-)

Seeing a similar thing happen with a field that has been typedefed to another (imported) class. It seems to not use the typedef name, and also doesn't import the underlying source file.

This is also causing problems for me, since I have a class that uses two libraries that have classes with the same name, so obviously i have to import as at least one of them, but since this extension doesn't recognise namespaced imports, it fails.