Closed
Description
Hi there,
I m raising this as an issue, as I don't know where to ask the question or if it's my fault.
As I was following tutorial MDC-104, after implementing the Backdrop, when I try to compile the app, I receive the following error:
Running 'gradlew assembleDebug'...
compiler message: lib/app.dart:34:35: Error: A value of type '#lib1::Category' can't be assigned to a variable of type '#lib2::Category'.
compiler message: Try changing the type of the left hand side, or casting the right hand side to '#lib2::Category'.
compiler message: currentCategory: Category.all,
compiler message: ^
Compiler failed on ~/mdc_100_series/lib/main.dart
This is the line that fails:
// TODO: Change home: to a Backdrop with a HomePage frontLayer (104)
home: Backdrop(
// TODO: Make currentCategory field take _currentCategory (104)
currentCategory: Category.all,
And below is the implementation as per the tutorial documentation:
class Backdrop extends StatefulWidget {
final Category currentCategory;
final Widget frontLayer;
final Widget backLayer;
final Widget frontTitle;
final Widget backTitle;
const Backdrop(
{@required this.currentCategory,
@required this.frontLayer,
@required this.backLayer,
@required this.frontTitle,
@required this.backTitle})
: assert(currentCategory != null),
assert(frontLayer != null),
assert(backLayer != null),
assert(frontTitle != null),
assert(backTitle != null);
@override
_BackdropState createState() => _BackdropState();
}
Am I missing something?
Please see below my setup:
Flutter 0.5.1 • channel beta • https://github.com/flutter/flutter.git
Framework • revision c7ea3ca377 (8 weeks ago) • 2018-05-29 21:07:33 +0200
Engine • revision 1ed25ca7b7
Tools • Dart 2.0.0-dev.58.0.flutter-f981f09760
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.5.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
[✓] Android Studio (version 3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2018.1)
[✓] Connected devices (1 available)
Thank you.
Kind regards,
Adrian
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
michdud commentedon Jul 23, 2018
Hi! This looks somewhat similar to dart-lang/sdk#33076--does changing the import in
main.dart
forapp.dart
topackage:Shrine/app.dart
help?Thanks for reporting this issue! Please let me know if this fix works for you, and we can update the codelab so others don't run into the same problem.
ciobania commentedon Jul 23, 2018
Ah! Life saving!
Thank you for your help!
It compiles and works.
Questions:
michdud commentedon Jul 24, 2018
In #83, I updated the
app.dart
import for all codelabs. According to the Dart issue linked above, it seems like the problem only exists for imports in "an entry point" (e.g. library file with amain()
), so the imports in other files won't be affected.In a broader context, I believe the issue above also has a proposed solution to treat relative imports in entry points like package imports (although I'm not sure that this is the solution with which they'll end up going).
If you use an IDE, the Dart plugin should be using the Dart analyzer (which performs linting), or you can run
dartanalyzer
in the command line. However, there is not yet a warning in the Dart linter for relative imports in entry points (this is currently an open issue).(You can also use
dartfmt
to format your code.)PhooPyaeSone commentedon May 26, 2021
There'll be a conflict with Category Class from another file so I changed the name so-called Category from the Product model file to another name (for instance CategoryOne). I'm not sure that'll be the best solution but It works.