Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

Group type of variables #31

Closed
Hauglid opened this issue Jun 14, 2022 · 14 comments · Fixed by #32 or #36
Closed

Group type of variables #31

Hauglid opened this issue Jun 14, 2022 · 14 comments · Fixed by #32 or #36

Comments

@Hauglid
Copy link

Hauglid commented Jun 14, 2022

Is your feature request related to a problem? Please describe.
Variables are grouped, but I would much more prefer to group optionals, finals, normal vars.

Describe the solution you'd like
Separate different type of variables.

Example:
How it is today:

  final varA1 = 'varA1';
  String? varA2;
  String varA3 = 'varA3';
  final varB1 = 'varB1';
  String? varB2;
  String varB3 = 'varB3';
  final varC1 = 'varC1';
  String? varC2;
  String varC3 = 'varC3';

How I would prefer it to be:

  final varA1 = 'varA1';
  final varB1 = 'varB1';
  final varC1 = 'varC1';

  String varA3 = 'varA3';
  String varB3 = 'varB3';
  String varC3 = 'varC3';

  String? varA2;
  String? varB2;
  String? varC2;
@Hauglid Hauglid changed the title Group variables Group type of variables Jun 14, 2022
@Hauglid
Copy link
Author

Hauglid commented Jun 14, 2022

Amazing! Thanks a bunch

@gmlewis
Copy link
Owner

gmlewis commented Jun 14, 2022

Amazing! Thanks a bunch

No problem. Thanks for the suggestion, @Hauglid !

Version v0.1.8 should now contain these changes and is available in the VSCode Marketplace:
https://marketplace.visualstudio.com/items?itemName=gmlewis-vscode.flutter-stylizer

@Hauglid
Copy link
Author

Hauglid commented Jun 15, 2022

I tried this now, and it doesn't sort the variables. I tried with both true and false.

@gmlewis
Copy link
Owner

gmlewis commented Jun 15, 2022

Please copy/paste your config settings for this plugin here so we can figure out the problem.

You need to add the new groupAndSortVariableTypes: true as described in the readme for this to take effect.

It is important that this plugin continues to behave the same way as it did previously for other people which is why we need to add new flags when new behaviors are requested. I hope that makes sense.

@gmlewis gmlewis reopened this Jun 15, 2022
@Hauglid
Copy link
Author

Hauglid commented Jun 15, 2022

Yes, I understand the need for the flags.

This is the settings I have:

"flutterStylizer": {
  "groupAndSortGetterMethods": false,
  "groupAndSortVariableTypes": true,
  "memberOrdering": [
    "public-constructor",
    "named-constructors",
    "public-static-variables",
    "public-instance-variables",
    "public-override-variables",
    "private-static-variables",
    "private-instance-variables",
    "public-other-methods",
    "public-override-methods",
    "private-other-methods",
    "build-method"
  ],
  "sortOtherMethods": true
},

@Hauglid
Copy link
Author

Hauglid commented Jun 15, 2022

So I think I figured it out. Is the formatter only for Stateful/StatelessWidget?
I have a file claim.dart with class Claim extends Equatable where it doesn't work.

Edit:
It works on some widgets, but not all of them for some weird reason

@Hauglid
Copy link
Author

Hauglid commented Jun 15, 2022

I will try to make a minimal, reproducible example later today.

@gmlewis
Copy link
Owner

gmlewis commented Jun 15, 2022

Yikes... sounds like a bug!

I will try to make a minimal, reproducible example later today.

Fantastic, thank you! I'll work on fixing the bug when I get an example case.

@PawlikMichalMiquido
Copy link

Hey @Hauglid were you able to create the example?

I'm looking forward to using this feature as well 🤗

@Hauglid
Copy link
Author

Hauglid commented Jun 27, 2022

Hi. Sorry, not yet. Been busy at work. I will try to get it done soon.

@Hauglid
Copy link
Author

Hauglid commented Jun 27, 2022

Here is a model class with a lot of different variables types. I couple of things I noticed is that private vars and final are sorted by name, not type and name. I would guess that this is the same for static and const?

// ignore_for_file: unused_field

class User {
  User({
    required this.firstNameFinal,
    required this.idFinal,
    required this.lastNameFinal,
    required this.middleNameFinal,
    required this.phoneNumberFinal,
    required this.usernameFinal,
    required this.firstNameRegular,
    required this.idRegular,
    required this.lastNameRegular,
    required this.usernameRegular,
  });

  final String firstNameFinal;
  final int idFinal;
  final String lastNameFinal;
  final String? middleNameFinal;
  final String? phoneNumberFinal;
  final String usernameFinal;

  String firstNameRegular;
  int idRegular;
  String lastNameRegular;
  String usernameRegular;

  int? ageOptional;
  String? birthdateOptional;
  String? emailOptional;
  String? middleNameRegular;
  String? phoneNumberRegular;

  int? _agePrivate;
  String? _birthdatePrivate;
  String? _emailPrivate;
  final String _firstNamePrivate = 'Secret';
  final int _idPrivate = 0;
  final String _lastNamePrivate = 'Secret';
  String? _middleNamePrivate;
  final String _phoneNumberPrivate = 'Secret';
  final String _usernamePrivate = 'Secret';
}

@gmlewis
Copy link
Owner

gmlewis commented Jun 28, 2022

Ah! I get it now. Thank you for the example, @Hauglid ... that helps tremendously. I'll add support for the private vars as well.

@gmlewis
Copy link
Owner

gmlewis commented Jun 28, 2022

@Hauglid - please try out release v0.1.16 of the VS Code plugin when you get a chance and let me know if it fixes the issue for you. Thank you for your patience!

@Hauglid
Copy link
Author

Hauglid commented Jun 30, 2022

Great work! It seems to be working as intended now 💯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants