-
Notifications
You must be signed in to change notification settings - Fork 28.6k
More beautiful linear_gradient sample #99298
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2014 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 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'goldens_io.dart' if (dart.library.html) 'goldens_web.dart' as flutter_goldens; | ||
|
||
Future<void> testExecutable(FutureOr<void> Function() testMain) { | ||
// Enable golden file testing using Skia Gold. | ||
return flutter_goldens.testExecutable(testMain, namePrefix: 'api'); | ||
} |
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,5 @@ | ||
// Copyright 2014 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. | ||
|
||
export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable; |
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,8 @@ | ||
// Copyright 2014 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'; | ||
|
||
// package:flutter_goldens is not used as part of the test process for web. | ||
Future<void> testExecutable(FutureOr<void> Function() testMain) async => testMain(); |
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,39 @@ | ||
// Copyright 2014 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 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_api_samples/painting/gradient/linear_gradient.0.dart' | ||
as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('finds a gradient', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: example.MoodyGradient(), | ||
), | ||
); | ||
|
||
expect(find.byType(example.MoodyGradient), findsOneWidget); | ||
}); | ||
|
||
testWidgets('gradient matches golden', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: SizedBox( | ||
width: 800, | ||
height: 600, | ||
child: RepaintBoundary( | ||
child: example.MoodyGradient(), | ||
), | ||
), | ||
), | ||
); | ||
await expectLater( | ||
find.byType(example.MoodyGradient), | ||
matchesGoldenFile('linear_gradient.0_test.png'), | ||
); | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -25,15 +25,18 @@ const String _kFlutterRootKey = 'FLUTTER_ROOT'; | |
/// [goldenFileComparator] to an instance of [FlutterGoldenFileComparator] that | ||
/// works for the current test. _Which_ FlutterGoldenFileComparator is | ||
/// instantiated is based on the current testing environment. | ||
Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
/// | ||
/// When set, the `namePrefix` is prepended to the names of all gold images. | ||
Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async { | ||
const Platform platform = LocalPlatform(); | ||
if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) { | ||
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform); | ||
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice. It will probably scale better to other packages to have them set a prefix in the test config file. 👍 |
||
} else if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) { | ||
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform); | ||
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); | ||
} else if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) { | ||
goldenFileComparator = FlutterSkippingFileComparator.fromDefaultComparator( | ||
'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.' | ||
'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.', | ||
namePrefix: namePrefix | ||
); | ||
} else { | ||
goldenFileComparator = await FlutterLocalFileComparator.fromDefaultComparator(platform); | ||
|
@@ -91,6 +94,7 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator { | |
this.skiaClient, { | ||
this.fs = const LocalFileSystem(), | ||
this.platform = const LocalPlatform(), | ||
this.namePrefix, | ||
}); | ||
|
||
/// The directory to which golden file URIs will be resolved in [compare] and | ||
|
@@ -109,6 +113,9 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator { | |
@visibleForTesting | ||
final Platform platform; | ||
|
||
/// The prefix that is added to all golden names. | ||
final String? namePrefix; | ||
|
||
@override | ||
Future<void> update(Uri golden, Uint8List imageBytes) async { | ||
final File goldenFile = getGoldenFile(golden); | ||
|
@@ -173,8 +180,12 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator { | |
'Golden files in the Flutter framework must end with the file extension ' | ||
'.png.' | ||
); | ||
final String prefix = basedir.pathSegments[basedir.pathSegments.length - 2]; | ||
return Uri.parse('$prefix.$golden'); | ||
return Uri.parse(<String>[ | ||
if (namePrefix != null) | ||
namePrefix!, | ||
basedir.pathSegments[basedir.pathSegments.length - 2], | ||
golden.toString(), | ||
].join('.')); | ||
} | ||
} | ||
|
||
|
@@ -205,11 +216,13 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator { | |
final SkiaGoldClient skiaClient, { | ||
final FileSystem fs = const LocalFileSystem(), | ||
final Platform platform = const LocalPlatform(), | ||
String? namePrefix, | ||
}) : super( | ||
basedir, | ||
skiaClient, | ||
fs: fs, | ||
platform: platform, | ||
namePrefix: namePrefix, | ||
); | ||
|
||
/// Creates a new [FlutterPostSubmitFileComparator] that mirrors the relative | ||
|
@@ -221,6 +234,7 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator { | |
final Platform platform, { | ||
SkiaGoldClient? goldens, | ||
LocalFileComparator? defaultComparator, | ||
String? namePrefix, | ||
}) async { | ||
|
||
defaultComparator ??= goldenFileComparator as LocalFileComparator; | ||
|
@@ -233,7 +247,7 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator { | |
|
||
goldens ??= SkiaGoldClient(baseDirectory); | ||
await goldens.auth(); | ||
return FlutterPostSubmitFileComparator(baseDirectory.uri, goldens); | ||
return FlutterPostSubmitFileComparator(baseDirectory.uri, goldens, namePrefix: namePrefix); | ||
} | ||
|
||
@override | ||
|
@@ -283,11 +297,13 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator { | |
final SkiaGoldClient skiaClient, { | ||
final FileSystem fs = const LocalFileSystem(), | ||
final Platform platform = const LocalPlatform(), | ||
final String? namePrefix, | ||
}) : super( | ||
basedir, | ||
skiaClient, | ||
fs: fs, | ||
platform: platform, | ||
namePrefix: namePrefix, | ||
); | ||
|
||
/// Creates a new [FlutterPreSubmitFileComparator] that mirrors the | ||
|
@@ -300,6 +316,7 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator { | |
SkiaGoldClient? goldens, | ||
LocalFileComparator? defaultComparator, | ||
Directory? testBasedir, | ||
String? namePrefix, | ||
}) async { | ||
|
||
defaultComparator ??= goldenFileComparator as LocalFileComparator; | ||
|
@@ -318,6 +335,7 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator { | |
return FlutterPreSubmitFileComparator( | ||
baseDirectory.uri, | ||
goldens, platform: platform, | ||
namePrefix: namePrefix, | ||
); | ||
} | ||
|
||
|
@@ -367,8 +385,9 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator { | |
FlutterSkippingFileComparator( | ||
final Uri basedir, | ||
final SkiaGoldClient skiaClient, | ||
this.reason, | ||
) : super(basedir, skiaClient); | ||
this.reason, { | ||
String? namePrefix, | ||
}) : super(basedir, skiaClient, namePrefix: namePrefix); | ||
|
||
/// Describes the reason for using the [FlutterSkippingFileComparator]. | ||
/// | ||
|
@@ -380,12 +399,13 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator { | |
static FlutterSkippingFileComparator fromDefaultComparator( | ||
String reason, { | ||
LocalFileComparator? defaultComparator, | ||
String? namePrefix, | ||
}) { | ||
defaultComparator ??= goldenFileComparator as LocalFileComparator; | ||
const FileSystem fs = LocalFileSystem(); | ||
final Uri basedir = defaultComparator.basedir; | ||
final SkiaGoldClient skiaClient = SkiaGoldClient(fs.directory(basedir)); | ||
return FlutterSkippingFileComparator(basedir, skiaClient, reason); | ||
return FlutterSkippingFileComparator(basedir, skiaClient, reason, namePrefix: namePrefix); | ||
} | ||
|
||
@override | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.