Unverified Commit 92ad558e authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix turbulence seed for all tests with ink sparkles (#138757)

Fixes https://github.com/flutter/flutter/issues/138753

This makes sure that InkSparkles are always fixed for testing rather than random.
parent 358e3913
...@@ -201,6 +201,13 @@ class InkSparkle extends InteractiveInkFeature { ...@@ -201,6 +201,13 @@ class InkSparkle extends InteractiveInkFeature {
// Creates an element of randomness so that ink emanating from the same // Creates an element of randomness so that ink emanating from the same
// pixel have slightly different rings and sparkles. // 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; _turbulenceSeed = turbulenceSeed ?? math.Random().nextDouble() * 1000.0;
} }
...@@ -429,7 +436,9 @@ class InkSparkle extends InteractiveInkFeature { ...@@ -429,7 +436,9 @@ class InkSparkle extends InteractiveInkFeature {
class _InkSparkleFactory extends InteractiveInkFeatureFactory { class _InkSparkleFactory extends InteractiveInkFeatureFactory {
const _InkSparkleFactory() : turbulenceSeed = null; 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() { static void initializeShader() {
if (!_initCalled) { if (!_initCalled) {
......
...@@ -179,7 +179,7 @@ Future<void> _runM3Test(WidgetTester tester, String positionName, double distanc ...@@ -179,7 +179,7 @@ Future<void> _runM3Test(WidgetTester tester, String positionName, double distanc
key: repaintKey, key: repaintKey,
child: ElevatedButton( child: ElevatedButton(
key: buttonKey, key: buttonKey,
style: ElevatedButton.styleFrom(splashFactory: InkSparkle.constantTurbulenceSeedSplashFactory), style: ElevatedButton.styleFrom(),
child: const Text('Sparkle!'), child: const Text('Sparkle!'),
onPressed: () { }, onPressed: () { },
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment