Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Color as field failed generation #513

Closed
Solido opened this issue Sep 28, 2018 · 25 comments
Closed

Flutter Color as field failed generation #513

Solido opened this issue Sep 28, 2018 · 25 comments

Comments

@Solido
Copy link

Solido commented Sep 28, 2018

Using Color get color; error to

import 'package:built_value/built_value.dart';
import 'dart:ui';

part 'myclass.data.g.dart';

abstract class MyClass implements Built<MyClass, MyClassBuilder> {

  String get name;
  bool get completed;
  Color get color;

  @nullable
  String get description;

  MyClass._();

  factory MyClass([updates(MyClassBuilder b)]) = _$MyClass;
}

`
Please make the following changes to use BuiltValue:

  1. Make field color have non-dynamic type. If you are already specifying a type, please make sure the type is correctly imported.
    [`

I've try using dart:ui or flutter/material as import, Type is recognised by the IDE but not when using built_value. Not sure what I missed.

Thank you.

@davidmorgan
Copy link
Collaborator

Unfortunately this is an issue with package:build, which built_value codegen is based upon.

dart-lang/build#733

The problem is that it runs codegen against the plain Dart SDK, not the Flutter SDK, so the tool cannot see dart:ui classes.

I suggest asking on that linked issue if there is a workaround.

@Solido
Copy link
Author

Solido commented Sep 28, 2018

I used the int color.value as replacement.
it does however lead to instantiate new Color object each time ...

@davidmorgan
Copy link
Collaborator

Closing this as a duplicate of #282

@kennethnym
Copy link

What version of build_runner fixed this issue? I just installed this package with built_value: but im still getting the same issue. Thank you!

@davidmorgan
Copy link
Collaborator

This was the commit to package:build:

dart-lang/build#2501

I think it's in the latest version, 1.2.1. It looks like that means build_runner 1.7.1 or higher.

@kennethnym
Copy link

Unfortunately I got the same error :(

I pinned build_runner on version 1.7.1:

build_runner: 1.7.1

Here is the code:

import 'package:built_value/built_value.dart';
import 'package:flutter/widgets.dart' show Color;

part 'theme.g.dart';

abstract class Theme implements Built<Theme, ThemeBuilder> {
  String get fontFamily;
  Color get primaryColor;
  Color get textColor;
  Color get backgroundColor;

  Theme._();
  factory Theme([void Function(ThemeBuilder) updates]) = _$Theme;
}

One of the errors:

1. Make field primaryColor have non-dynamic type. If you are already specifying a type, please make sure the type is correctly imported.

@davidmorgan
Copy link
Collaborator

Have filed an issue over at package:build :)

Thanks.

@kennethnym
Copy link

Thank you so much!

@jakemac53
Copy link
Contributor

Copying comment from that issue, the fix is in build_resolvers not the build or build_runner, you will need version 1.2.1 of build_resolvers or greater.

@kennethnym
Copy link

So that means i need to explicitly install build_resolvers? Does built_value (or build_runner) not specify its own version of build_resolvers?

@jakemac53
Copy link
Contributor

jakemac53 commented Oct 31, 2019

You should be able to do a normal pub upgrade (for flutter packages pub upgrade) - it is a transitive dependency of build/build_runner.

The output of that command should show you the versions that were selected and so as long as you get at least version 1.2.1 you should be good. If you don't get that version you would have to figure out why - one of the easier ways to do that would be to add the dependency temporarily and re-run the command.

@kennethnym
Copy link

Will try that. Thank you so much!

@kennethnym
Copy link

kennethnym commented Oct 31, 2019

Upgraded packages. build_runner is on 1.7.1 and build on 1.2.1, but I am still having the same issue.

Edit: flutter pub deps results in:

|-- build_runner 1.7.1
|   |-- args 1.5.2
|   |-- async 2.3.0
|   |   '-- collection...
|   |-- build 1.2.1
|   |   |-- analyzer...
|   |   |-- async...
|   |   |-- convert...
|   |   |-- crypto...
|   |   |-- glob...
|   |   |-- logging...
|   |   |-- meta...
|   |   '-- path...

@jakemac53
Copy link
Contributor

What is the build_resolvers version though?

@kennethnym
Copy link

On 1.2.1

@jakemac53
Copy link
Contributor

And are you running flutter pub run build_runner ... or pub run build_runer ...?

@kennethnym
Copy link

flutter pub run build_runner build

@jakemac53
Copy link
Contributor

jakemac53 commented Oct 31, 2019

I just tried this for the examples/hello_world (in the flutter repo), adding the theme example above as lib/theme.dart and I got the following theme.g.dart file https://gist.github.com/jakemac53/9260b9b1c6ddd8ed53273bb8afb46359.

That looks like it worked to me - so something else might be going on. If that doesn't look like what is expected please let me know.

Can you try deleting your .dart_tool/build_resolvers directory as well?

@kennethnym
Copy link

So I tried:

  1. Deleting .dart_tool in my existing project;
  2. Creating a new project, installing the packages, copying the class, and running build; and
  3. restarting my computer.

I am having issues in both projects, and the issue persists after the reboot :(

@jakemac53
Copy link
Contributor

@MrCreeper1008 what flutter version? Can you provide your entire pubspec.lock file? Ideally for the simplest example (the new project with the class copied).

@kennethnym
Copy link

Absolutely! I am on Flutter 1.9.1+hotfix6. Here is the lock file for the new project I created.

@jakemac53
Copy link
Contributor

Ok - good news is I was able to reproduce the issue with that flutter version and pubspec.lock! Now to try and find the problem :).

@kennethnym
Copy link

Thank you so much for the help!

@jakemac53
Copy link
Contributor

Fyi I re-opened the build issue that @davidmorgan filed based on this dart-lang/build#2528. I might do some followup there that I don't copy here but I will update this thread as well once the issue is resolved one way or the other.

@kennethnym
Copy link

Thank you! Will subscribe to that issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants