This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
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
Merged
fluttergithubbot
merged 17 commits into
flutter:master
from
ValentinVignal:use-transparent-image
Oct 29, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dd83135
:bug: Use a transparent image as a placeholder
ValentinVignal 4ffd27f
:bookmark: Modify version in pubspec and CHANGELOG
ValentinVignal 8008688
:white_check_mark: Write a test to make sur the GoogleUserCircleAvata…
ValentinVignal 8048451
:art: _kTransparentImage -> _transparentImage as it is not a const
ValentinVignal 75725ef
:page_facing_up: Add license block to test/widgets_test.dart
ValentinVignal a54232d
🏷️ Use fixed-width hex
ValentinVignal 9a9d6d4
:fire: Remove unused constructor parameter
ValentinVignal b18a8e2
:recycle: Use Fake
ValentinVignal d25857f
Merge remote-tracking branch 'upstream/master' into use-transparent-i…
ValentinVignal 316afbf
🔀 Fix merge conflict with master. Update version number and override…
ValentinVignal 166822e
:art: Use comment to format data blobs
ValentinVignal 03c48da
:bulb: Improve comment of _transparentImage
ValentinVignal bf0f524
:pencil2: Fix typo in test description
ValentinVignal 1d2638a
:bulb: Add another forgotten "."
ValentinVignal 4d17090
:bento: Add resources/transparentImage.gif
ValentinVignal 6c69b63
Fix comment
stuartmorgan 3291d1b
Fix comment
stuartmorgan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
`transparentImage.gif` is a 1x1 transparent gif which comes from [this wikimedia page](https://commons.wikimedia.org/wiki/File:Transparent.gif): | ||
|
||
 | ||
|
||
This is the image used a placeholder for the `GoogleCircleAvatar` widget. | ||
|
||
The variable `_transparentImage` in `lib/widgets.dart` is the list of bytes of `transparentImage.gif`. |
Binary file added
BIN
+42 Bytes
packages/google_sign_in/google_sign_in/resources/transparentImage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions
117
packages/google_sign_in/google_sign_in/test/widgets_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
/// A instantiable class that extends [GoogleIdentity] | ||
class _TestGoogleIdentity extends GoogleIdentity { | ||
_TestGoogleIdentity({ | ||
required this.id, | ||
required this.email, | ||
this.photoUrl, | ||
}); | ||
|
||
final String id; | ||
final String email; | ||
|
||
final String? photoUrl; | ||
|
||
@override | ||
String? get displayName => null; | ||
|
||
@override | ||
String? get serverAuthCode => null; | ||
} | ||
|
||
/// A mocked [HttpClient] which always returns a [_MockHttpRequest]. | ||
class _MockHttpClient extends Fake implements HttpClient { | ||
@override | ||
bool autoUncompress = true; | ||
|
||
@override | ||
Future<HttpClientRequest> getUrl(Uri url) { | ||
return Future<HttpClientRequest>.value(_MockHttpRequest()); | ||
} | ||
} | ||
|
||
/// A mocked [HttpClientRequest] which always returns a [_MockHttpClientResponse]. | ||
class _MockHttpRequest extends Fake implements HttpClientRequest { | ||
@override | ||
Future<HttpClientResponse> close() { | ||
return Future<HttpClientResponse>.value(_MockHttpResponse()); | ||
} | ||
} | ||
|
||
/// Arbitrary valid image returned by the [_MockHttpResponse]. | ||
/// | ||
/// This is an transparent 1x1 gif image. | ||
/// It doesn't have to match the placeholder used in [GoogleUserCircleAvatar]. | ||
/// | ||
/// Those bytes come from `resources/transparentImage.gif`. | ||
final Uint8List _transparentImage = Uint8List.fromList( | ||
[ | ||
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, // | ||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x21, 0xf9, 0x04, 0x01, 0x00, // | ||
0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, // | ||
0x00, 0x02, 0x01, 0x44, 0x00, 0x3B | ||
], | ||
); | ||
|
||
/// A mocked [HttpClientResponse] which is empty and has a [statusCode] of 200 | ||
/// and returns valid image. | ||
class _MockHttpResponse extends Fake implements HttpClientResponse { | ||
final Stream<Uint8List> _delegate = | ||
Stream<Uint8List>.value(_transparentImage); | ||
|
||
@override | ||
int get contentLength => -1; | ||
|
||
@override | ||
HttpClientResponseCompressionState get compressionState { | ||
return HttpClientResponseCompressionState.decompressed; | ||
} | ||
|
||
@override | ||
StreamSubscription<Uint8List> listen(void Function(Uint8List event)? onData, | ||
{Function? onError, void Function()? onDone, bool? cancelOnError}) { | ||
return _delegate.listen(onData, | ||
onError: onError, onDone: onDone, cancelOnError: cancelOnError); | ||
} | ||
|
||
@override | ||
int get statusCode => 200; | ||
} | ||
|
||
void main() { | ||
testWidgets('It should build the GoogleUserCircleAvatar successfully', | ||
(WidgetTester tester) async { | ||
final GoogleIdentity identity = _TestGoogleIdentity( | ||
email: '[email protected]', | ||
id: 'userId', | ||
photoUrl: 'photoUrl', | ||
); | ||
tester.binding.window.physicalSizeTestValue = Size(100, 100); | ||
|
||
await HttpOverrides.runZoned( | ||
() async { | ||
await tester.pumpWidget(MaterialApp( | ||
home: SizedBox( | ||
height: 100, | ||
width: 100, | ||
child: GoogleUserCircleAvatar( | ||
identity: identity, | ||
), | ||
), | ||
)); | ||
}, | ||
createHttpClient: (SecurityContext? c) => _MockHttpClient(), | ||
); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
plugin/packages/<new package>
transparentImage
(not private)transparentImage
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:
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!