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

Avoid cumbersome formatter workaround #6573

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

lrhn
Copy link

@lrhn lrhn commented Apr 19, 2024

If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter. Much simpler.

If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter.
Much simpler.
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

RegExp(r' *0x([A-F0-9]{2}),? *\n? *'), (Match m) => '${m[1]}\n'))
.map<int>((String b) => int.parse(b, radix: 16))
.toList();
];
Copy link
Author

@lrhn lrhn Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another, still simpler than the original, workaround would be:

final String _imageBytesString =
  '\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49'
  '\x48\x44\x52\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06'
  '\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00\x0A\x49\x44'
  '\x41\x54\x78\x9C\x63\x00\x01\x00\x00\x05\x00\x01\x0D'
  '\x0A\x2D\xB4\x00\x00\x00\x00\x49\x45\x4E\x44\xAE';
final List<int> _transparentImage = [..._imageBytesString.codeUnits];

Having a full, formatted string, and parsing it using RegExp, just to get to some bytes, feels a little like overkill.


// Convert the string representing the hexidecimal bytes in the image into
// a list of integers that can be consumed as image data in a stream.
final List<int> _transparentImage = const LineSplitter()
Copy link
Author

@lrhn lrhn Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some possible improvements, for any similar code:

  • For const LineSplitter().convert(...), one can just use LineSplitter.split(...).
  • It's easier to just match the numbers, and then work on allMatches, than to try to remove what's not numbers:
    final List<int> _transparentImage = RegExp(r'0x([A-F0-9]{2})').allMatches(_imageBytesAsString)
        .map((b) => int.parse(b[1], radix: 16))
        .toList();

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