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.
This commit is contained in:
Kate Lovett
2023-11-28 11:59:19 -06:00
committed by GitHub
parent 358e39137f
commit 92ad558e25
2 changed files with 11 additions and 2 deletions

View File

@@ -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;
}
@@ -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) {

View File

@@ -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: () { },
),