Skip to content

Commit

Permalink
Fix turbulence seed for all tests with ink sparkles (#138757)
Browse files Browse the repository at this point in the history
Fixes flutter/flutter#138753

This makes sure that InkSparkles are always fixed for testing rather than random.
  • Loading branch information
Piinks authored Nov 28, 2023
1 parent 358e391 commit 92ad558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/flutter/lib/src/material/ink_sparkle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ class InkSparkle extends InteractiveInkFeature {

// Creates an element of randomness so that ink emanating from the same
// pixel have slightly different rings and sparkles.
assert((){
// In tests, randomness can cause flakes. So if a seed has not
// already been specified (i.e. for the purpose of the test), set it to
// the constant turbulence seed.
turbulenceSeed ??= _InkSparkleFactory.constantSeed;
return true;
}());
_turbulenceSeed = turbulenceSeed ?? math.Random().nextDouble() * 1000.0;
}

Expand Down Expand Up @@ -429,7 +436,9 @@ class InkSparkle extends InteractiveInkFeature {
class _InkSparkleFactory extends InteractiveInkFeatureFactory {
const _InkSparkleFactory() : turbulenceSeed = null;

const _InkSparkleFactory.constantTurbulenceSeed() : turbulenceSeed = 1337.0;
const _InkSparkleFactory.constantTurbulenceSeed() : turbulenceSeed = _InkSparkleFactory.constantSeed;

static const double constantSeed = 1337.0;

static void initializeShader() {
if (!_initCalled) {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/ink_sparkle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Future<void> _runM3Test(WidgetTester tester, String positionName, double distanc
key: repaintKey,
child: ElevatedButton(
key: buttonKey,
style: ElevatedButton.styleFrom(splashFactory: InkSparkle.constantTurbulenceSeedSplashFactory),
style: ElevatedButton.styleFrom(),
child: const Text('Sparkle!'),
onPressed: () { },
),
Expand Down

0 comments on commit 92ad558

Please sign in to comment.