gmlewis / flutter-stylizer

Flutter Stylizer is a VSCode extension that organizes your Flutter classes and mixins in an opinionated and consistent manner.
https://marketplace.visualstudio.com/items?itemName=gmlewis-vscode.flutter-stylizer
Apache License 2.0
23 stars 3 forks source link

Group type of variables #31

Closed Hauglid closed 2 years ago

Hauglid commented 2 years ago

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 commented 2 years ago

Amazing! Thanks a bunch

gmlewis commented 2 years ago

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 commented 2 years ago

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

gmlewis commented 2 years ago

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.

Hauglid commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

gmlewis commented 2 years ago

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 commented 2 years ago

Hey @Hauglid were you able to create the example?

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

Hauglid commented 2 years ago

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

Hauglid commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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