diff --git a/packages/flutter/lib/src/material/ink_sparkle.dart b/packages/flutter/lib/src/material/ink_sparkle.dart index d4d107735bc2..798604985aec 100644 --- a/packages/flutter/lib/src/material/ink_sparkle.dart +++ b/packages/flutter/lib/src/material/ink_sparkle.dart @@ -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) { diff --git a/packages/flutter/test/material/ink_sparkle_test.dart b/packages/flutter/test/material/ink_sparkle_test.dart index 40b47d762517..ca7c454d86b5 100644 --- a/packages/flutter/test/material/ink_sparkle_test.dart +++ b/packages/flutter/test/material/ink_sparkle_test.dart @@ -179,7 +179,7 @@ Future _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: () { }, ),