Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in] Use a transparent image as a placeholder for the GoogleUserCircleAvatar #4391

Merged
merged 17 commits into from
Oct 29, 2021

Conversation

ValentinVignal
Copy link
Contributor

@ValentinVignal ValentinVignal commented Sep 28, 2021

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

Use a valid transparent 1 x 1 image for the placeholder of the GoogleUserCircleAvatar (Uint8List((size.round() * size.round())), is not a valid image).

List which issues are fixed by this PR. You must list at least one issue.

flutter/flutter#88329
flutter/flutter#55639

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

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

@google-cla
Copy link

google-cla bot commented Sep 28, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@ValentinVignal ValentinVignal marked this pull request as ready for review September 30, 2021 13:55
@ValentinVignal
Copy link
Contributor Author

ValentinVignal commented Sep 30, 2021

I'm not proud of the test I have written at all. It works though, this is a failing test without the changes I have made:

00:02 +0: It should build th GoogleUserCircleAvatar successfully                                                                                       
photoUrl photoUrl
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following _Exception was thrown resolving an image codec:
Exception: Invalid image data

When the exception was thrown, this was the stack:
#0      _futurize (dart:ui/painting.dart:5502:5)
#1      ImageDescriptor.encoded (dart:ui/painting.dart:5370:12)
#2      instantiateImageCodec (dart:ui/painting.dart:2053:60)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════
00:02 +0 -1: It should build th GoogleUserCircleAvatar successfully [E]                                                                                
  Test failed. See exception logs above.
  The test description was: It should not raise an exception

I had to override the HttpClient and it takes 500 lines... I took the code from https://github.com/flutter/flutter/blob/master/packages/flutter_test/lib/src/_binding_io.dart

I set _transparentImage as a private variable because I guess we don't want to export it.
But because of that, I had to create this variable twice: one time in lib/widgets.dart and one time in test/widgets_test.dart.

How can I improve what I have done?

@stuartmorgan stuartmorgan self-requested a review September 30, 2021 20:07
68,
1,
0,
59,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: data bytes are generally written as fixed-width hex (e.g., 0x00 rather than 0, 0xFF rather than 255)

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've changed it in a54232d

_TestGoogleIdentity({
required this.id,
required this.email,
this.displayName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a constructor argument that is never used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for that, I removed it in 9a9d6d4

}

/// A mocked [HttpClient] which always returns a [_MockHttpRequest].
class _MockHttpClient implements HttpClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

class _MockHttpClient extends Fake implements HttpClient would eliminate quite a bit of code here.

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 used Fake in b18a8e2


/// A mocked [HttpClientResponse] which is empty and has a [statusCode] of 200
/// and returns a 1x1 transparent image.
class _MockHttpResponse implements HttpClientResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fake seems very likely to help here as well.

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 used Fake in b18a8e2

…mage

# Conflicts:
#	packages/google_sign_in/google_sign_in/CHANGELOG.md
#	packages/google_sign_in/google_sign_in/pubspec.yaml
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Minor nits, but otherwise looks good now. Thanks!

/// This is an transparent 1x1 gif image
final Uint8List _transparentImage = Uint8List.fromList(
[
0x47,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can improve these data blobs by adding a // somewhere and then removing most of the newlines.

E.g.:

final Uint8List _transparentImage = Uint8List.fromList(
  [
    0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, //
    0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04, 0x01, 0x00,
    0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
...

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've formatter the data blobs in 166822e

/// This is an transparent 1x1 gif image
final Uint8List _transparentImage = Uint8List.fromList(
[
0x47,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same formatting note here.

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've formatter the data blobs in 166822e

image: sizedPhotoUrl,
)
]),
));
}
}

/// This is an transparent 1x1 gif image
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should have a "." at the end of the comment.

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 added the "." in 03c48da

}
}

/// This is an transparent 1x1 gif image
Copy link
Contributor

Choose a reason for hiding this comment

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

Please comment that this is just an arbitrary valid image, and that it's not important that it match the placeholder, since that confused me.

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've tried to add a better comment in 03c48da

);

/// A mocked [HttpClientResponse] which is empty and has a [statusCode] of 200
/// and returns a 1x1 transparent image.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/1x1 transparent/valid/ since that's what matters.

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 changed it in 03c48da

}

void main() {
testWidgets('It should build th GoogleUserCircleAvatar successfully',
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: the

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 have fixed the typo in bf0f524

@stuartmorgan
Copy link
Contributor

Adding @gaaclarke for secondary review.

image: sizedPhotoUrl,
)
]),
));
}
}

/// This is an transparent 1x1 gif image
final Uint8List _transparentImage = Uint8List.fromList(
Copy link
Member

Choose a reason for hiding this comment

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

You should check in a script that generates this code and add a comment here pointing to it.

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'm sorry, I'm a bit confused and I don't understand what you want me to do?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should check in a script that generates this code

Why? Under what circumstance would the bytes of a static image need to be re-generated?

Copy link
Member

Choose a reason for hiding this comment

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

Presumably a script was already written to generate it. Who knows, maybe there is a bug where the pixel is #000000FF but we need #FFFFFFFF, depending on alpha blending that can make a difference. Plus it means people don't need to execute the code to know it is correct. I don't know the gif header format.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternately, we could compare it byte by byte to the source, which would be significantly less work than reviewing (and then maintaining) a script.

@ValentinVignal Can you add a comment with the URL of the source gif you used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea. So let's land the gif (maybe in a new package-level directory with a README explaining why it's there), and reference it in a comment in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, I'm sorry again, I'm still not clear on what I should do exactly. Let me try to reformulate and you tell me if I'm wrong?


I should:

  1. Create a new package in plugin/packages/<new package>
  2. Add the gif image as an asset and this variable transparentImage (not private)
  3. Import this package in google_sign_in to reuse the variable transparentImage
  4. Write a test in the new repo to read the bytes of the gif image and compare them to the ones in the variable

Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you just need to add the source GIF to this PR. My suggestion is that it be in a subdirectory (e.g., resources/) with a README, rather than being at the top level of the plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stuartmorgan @gaaclarke I couldn't remember where I took the image in the first place.

In 4d17090, I used this one:

from this wikimedia page.

I added the image in the repo as resources/transparentImage.gif and updated the bytes of _transparentImage to match the gif file.

I got the bytes by doing:

final bytes = await File('resources/transparentImage.gif').readAsBytes();

Is it what you were requesting?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that sounds good to me, thanks!

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke can do the second review

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

LGTM modulo the code to generate the data blob. Without demonstrating the generation of the bytes I don't know if it really is 1x1 pixel or what the color of that pixel is.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Changes LGTM

@stuartmorgan stuartmorgan added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Oct 29, 2021
@fluttergithubbot fluttergithubbot merged commit 7588dd9 into flutter:master Oct 29, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2021
NickalasB added a commit to NickalasB/plugins that referenced this pull request Nov 4, 2021
* master:
  [webview_flutter] Deprecate evaluateJavascript in favour of runJavaScript and runJavaScriptForResult. (flutter#4403)
  [webview_flutter] Add interface methods to load local files and HTML strings. (flutter#4446)
  [ci] add pedantic dep to new in_app_purchase pkgs (flutter#4471)
  [ci] Remove unused dep from file_selector. (flutter#4468)
  [ci] update build_runner dep in android_intent and file_selector example (flutter#4467)
  [webview_flutter] Add platform interface method `loadRequest`. (flutter#4450)
  Remove -Werror from deprecated plugin Android builds (flutter#4466)
  [webview_flutter] Update webview packages for Android and iOS to implement `runJavascript` and `runJavascriptReturningResult`. (flutter#4402)
  [camera] Fix CamcorderProfile Usages (flutter#4423)
  [google_sign_in] Use a transparent image as a placeholder for the `GoogleUserCircleAvatar` (flutter#4391)
  [in_app_purchase]IAP/platform interface add cancel status (flutter#4093)
  [image_picker] doc:readme image picker misprints (flutter#4421)
  Support Hybrid Composition through the GoogleMaps Widget (flutter#4082)
  [path_provider] started supporting background platform channels (flutter#4443)
  [device_info] started using Background Platform Channels (flutter#4456)

# Conflicts:
#	packages/webview_flutter/webview_flutter/CHANGELOG.md
#	packages/webview_flutter/webview_flutter/pubspec.yaml
amantoux pushed a commit to amantoux/plugins that referenced this pull request Dec 11, 2021
KyleFin pushed a commit to KyleFin/plugins that referenced this pull request Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: google_sign_in waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants