-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_sign_in] Use a transparent image as a placeholder for the GoogleUserCircleAvatar
#4391
[google_sign_in] Use a transparent image as a placeholder for the GoogleUserCircleAvatar
#4391
Conversation
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. ℹ️ Googlers: Go here for more info. |
1b15fe4
to
dd83135
Compare
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:
I had to override the I set How can I improve what I have done? |
68, | ||
1, | ||
0, | ||
59, |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
…serverAuthCode in test
There was a problem hiding this 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, |
There was a problem hiding this comment.
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,
...
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same formatting note here.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: the
There was a problem hiding this comment.
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
Adding @gaaclarke for secondary review. |
image: sizedPhotoUrl, | ||
) | ||
]), | ||
)); | ||
} | ||
} | ||
|
||
/// This is an transparent 1x1 gif image | ||
final Uint8List _transparentImage = Uint8List.fromList( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Create a new package in
plugin/packages/<new package>
- Add the gif image as an asset and this variable
transparentImage
(not private) - Import this package in google_sign_in to reuse the variable
transparentImage
- 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this 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
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM
… the `GoogleUserCircleAvatar` (flutter/plugins#4391)
… the `GoogleUserCircleAvatar` (flutter/plugins#4391)
… the `GoogleUserCircleAvatar` (flutter/plugins#4391)
* 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
…ogleUserCircleAvatar` (flutter#4391)
…ogleUserCircleAvatar` (flutter#4391)
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
dart format
.)[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.