Skip to content

Refactor Dart counter sample to use shared package#1267

Merged
jhuleatt merged 1 commit intocodelab-dartfrom
dart-counter-shared-refactor-16206636299737686696
Apr 10, 2026
Merged

Refactor Dart counter sample to use shared package#1267
jhuleatt merged 1 commit intocodelab-dartfrom
dart-counter-shared-refactor-16206636299737686696

Conversation

@jhuleatt
Copy link
Copy Markdown
Collaborator

Refactored the Dart counter sample by introducing a shared package and updating the main server script to leverage it, fixing some syntax errors along the way.


PR created automatically by Jules for task 16206636299737686696 started by @jhuleatt

- Created a new `shared` package to hold `IncrementResponse` and `incrementCallable`.
- Updated `https-increment-number/pubspec.yaml` to depend on the `shared` package.
- Replaced `https-increment-number/bin/server.dart` with updated user code, fixing syntax errors.
- Added appropriate `.gitignore` files to exclude generated Dart tooling and locks.

Co-authored-by: jhuleatt <3759507+jhuleatt@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Dart HTTPS increment number quickstart by introducing a shared package for common data structures and constants. The server logic was updated to handle both GET and POST requests for a synchronized counter using Firestore atomic increments. Review feedback highlighted a runtime type error when extracting the increment step from query parameters, a discrepancy in the returned count value which failed to account for the step size, and an invalid SDK version constraint in the shared package's configuration.

);
} else if (request.method == 'POST') {
// Increment count by one
final step = request.url.queryParameters['step'] as int? ?? 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The cast as int? will cause a runtime TypeError because request.url.queryParameters returns a Map<String, String>. You should use int.tryParse to safely convert the string value to an integer.

Suggested change
final step = request.url.queryParameters['step'] as int? ?? 1;
final step = int.tryParse(request.url.queryParameters['step'] ?? '') ?? 1;

incrementResponse = IncrementResponse(
success: true,
message: 'Atomic increment complete',
newCount: value + 1,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The newCount returned in the response should reflect the actual increment value specified by the step variable, rather than being hardcoded to value + 1.

Suggested change
newCount: value + 1,
newCount: value + step,

publish_to: none

environment:
sdk: ^3.11.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The SDK version constraint ^3.11.0 appears to be a typo, as Dart 3.11 has not been released yet. This will prevent the package from being resolved on current stable Dart versions. Consider using a valid version like ^3.0.0.

  sdk: ^3.0.0

@jhuleatt jhuleatt merged commit 2ebee4d into codelab-dart Apr 10, 2026
2 checks passed
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.

1 participant