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

Add crossword sample #56

Merged
merged 5 commits into from
Jun 30, 2024
Merged

Conversation

domesticmouse
Copy link
Contributor

@domesticmouse domesticmouse commented May 30, 2024

Fixes: flutter/flutter#149286

Pre-launch Checklist

  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I read the Contributors Guide.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel channel on Discord.

@domesticmouse domesticmouse requested a review from filiph May 30, 2024 01:06
Copy link
Contributor

@filiph filiph left a comment

Choose a reason for hiding this comment

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

LGTM with some random comments.

static int locationComparator(CrosswordWord a, CrosswordWord b) {
final compareRows = a.location.y.compareTo(b.location.y);
final compareColumns = a.location.x.compareTo(b.location.x);
return switch (compareColumns) { 0 => compareRows, _ => compareColumns };
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] A little too fancy for my taste, but that's okay. I think this should have a trailing comma so that the cases are below each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

samples/crossword/lib/model.dart Show resolved Hide resolved
Comment on lines +19 to +34
/// An extension on [Duration] that adds a method to format the duration.
extension DurationFormat on Duration {
/// A human-readable string representation of the duration.
/// This format is tuned for durations in the seconds to days range.
String get formatted {
final hours = inHours.remainder(24).toString().padLeft(2, '0');
final minutes = inMinutes.remainder(60).toString().padLeft(2, '0');
final seconds = inSeconds.remainder(60).toString().padLeft(2, '0');
return switch ((inDays, inHours, inMinutes, inSeconds)) {
(0, 0, 0, _) => '${inSeconds}s',
(0, 0, _, _) => '$inMinutes:$seconds',
(0, _, _, _) => '$inHours:$minutes:$seconds',
_ => '$inDays days, $hours:$minutes:$seconds',
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very nice and I'm probably going to steal this.

duration: Durations.extralong1,
curve: Curves.easeInOut,
color: explorationCell
? Theme.of(context).colorScheme.primary
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Lots of Theme.of(context).colorScheme. Could be extracted to a local variable at the top of the function: both for readability and (tiny) perf improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 44 to 46
.rebuild(
(b) => b.where((b) => b.direction == Direction.across),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really need a rebuild step? Is there no where on built lists? Or at least toList().where()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got into the habit of always rebuilding. To save the .toBuiltList() call.

@domesticmouse domesticmouse added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 30, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 30, 2024
Copy link

auto-submit bot commented Jun 30, 2024

auto label is removed for flutter/games/56, due to - The status or check suite Test Flutter beta on windows-latest has failed. Please fix the issues identified (or deflake) before re-applying this label.

@domesticmouse domesticmouse merged commit 9c8dd97 into flutter:main Jun 30, 2024
6 of 7 checks passed
@domesticmouse domesticmouse deleted the crossword-sample branch June 30, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Game] New Crossword template
2 participants