trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.08k stars 246 forks source link

Use 'const' for final variables initialized to a constant value. Try replacing 'final' with 'const'. #652

Open liyofx opened 8 months ago

liyofx commented 8 months ago

image

emintolgahanpolat commented 8 months ago

I think removing it from analysis is a better solution. Because having the code generator check these cases can cause a lot of confusion.

Warnings can be hidden from the analysis_options.yaml file.

include: package:flutter_lints/flutter.yaml analyzer: exclude: [ build/**, lib/**.g.dart ] linter:

JuKu commented 8 months ago

@emintolgahanpolat But this doesn't solve the underlying problem. As I know, a const field is more performant, than a final field.

emintolgahanpolat commented 8 months ago

@JuKu Yes you are right, a const field is more performant, than a final field.

But if _data wasn't null we couldn't use const. const_initialized_with_non_constant_value

If _data is null, const can be used. Do you think this will solve the problem?

emintolgahanpolat commented 8 months ago
image

If you think this will solve the problem I can create a PR.

JuKu commented 8 months ago

@emintolgahanpolat I think this should work! :) And it should solve the problem very well.

Btw, I think these are the rules from the Flutter analyzer:

I think only the last rule is relevant for us, or?