Skip to content

Commit 92ad558

Browse files
authored
Fix turbulence seed for all tests with ink sparkles (#138757)
Fixes flutter/flutter#138753 This makes sure that InkSparkles are always fixed for testing rather than random.
1 parent 358e391 commit 92ad558

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/flutter/lib/src/material/ink_sparkle.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ class InkSparkle extends InteractiveInkFeature {
201201

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

@@ -429,7 +436,9 @@ class InkSparkle extends InteractiveInkFeature {
429436
class _InkSparkleFactory extends InteractiveInkFeatureFactory {
430437
const _InkSparkleFactory() : turbulenceSeed = null;
431438

432-
const _InkSparkleFactory.constantTurbulenceSeed() : turbulenceSeed = 1337.0;
439+
const _InkSparkleFactory.constantTurbulenceSeed() : turbulenceSeed = _InkSparkleFactory.constantSeed;
440+
441+
static const double constantSeed = 1337.0;
433442

434443
static void initializeShader() {
435444
if (!_initCalled) {

packages/flutter/test/material/ink_sparkle_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Future<void> _runM3Test(WidgetTester tester, String positionName, double distanc
179179
key: repaintKey,
180180
child: ElevatedButton(
181181
key: buttonKey,
182-
style: ElevatedButton.styleFrom(splashFactory: InkSparkle.constantTurbulenceSeedSplashFactory),
182+
style: ElevatedButton.styleFrom(),
183183
child: const Text('Sparkle!'),
184184
onPressed: () { },
185185
),

0 commit comments

Comments
 (0)