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

[Proposal] Show error before runtime when using color param AND decoration param at the same time #133456

Closed
2 tasks done
Fernandomr88 opened this issue Aug 28, 2023 · 7 comments
Closed
2 tasks done
Labels
r: solved Issue is closed as solved

Comments

@Fernandomr88
Copy link

Fernandomr88 commented Aug 28, 2023

Is there an existing issue for this?

Use case

Whenever you're implementing a Container for example and you use both color and decoration at the same time, there's no error shown but an exception is thrown only when the widget is built in runtime, not even on compilation.
Code example:

Container(
  height: 150,
  width: 150,
  color: Colors.white, ///<- color
  decoration: BoxDecoration(borderRadius: BorderRadius.circular(100), color: Colors.white), //<- color again
  child: Image.asset(
    'assets/img/X.gif',
    height: 100,
  ),
));

image

Proposal

My proposal is that the error is shown on "coding time", just as any errors that are shown such as this one for example:

image

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Aug 29, 2023
@darshankawar
Copy link
Member

Thanks for the report @Fernandomr88
The example you gave in proposal section actually depicts a type check error and are most commonly thrown during coding time rather than runtime through Dart. You may read about the common type check problems here: https://dart.dev/guides/language/sound-problems

The one you highlighted related to Container is actually a code implementation issue which has been documented for reference:

/// The `color` and `decoration` arguments cannot both be supplied, since
  /// it would potentially result in the decoration drawing over the background
  /// color. To supply a decoration with a color, use `decoration:
  /// BoxDecoration(color: color)`.

I am not sure if the tool / framework will be able to identify whether color and decoration properties are being used during coding time.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 29, 2023
@Fernandomr88
Copy link
Author

Fernandomr88 commented Aug 29, 2023

I see, can it at least be detected during compile time or even by linter?

This could prevent some issues during production time, since that problem is only detected when that widget is rendered

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 29, 2023
@darshankawar
Copy link
Member

I think there's no way to ensure that an assert is run at compile time. I see this similar issue you can check for reference which probably talks about same case as yours but just for another widget.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 30, 2023
@Fernandomr88
Copy link
Author

I think there's no way to ensure that an assert is run at compile time. I see this similar issue you can check for reference which probably talks about same case as yours but just for another widget.

How about at flutter linter? 🤔 My point is that this could prevent problems, exceptions and crashes at runtime

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 30, 2023
@darshankawar
Copy link
Member

How about at flutter linter?

You may file a proposal for that package https://pub.dev/packages/flutter_lints. Although it'll be in same repo as this, but just using the package template.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 31, 2023
@Fernandomr88
Copy link
Author

done

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 31, 2023
@darshankawar darshankawar added r: solved Issue is closed as solved and removed in triage Presently being triaged by the triage team labels Aug 31, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

2 participants