slider_theme_test.dart 46.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:ui' show window;

7
import 'package:flutter/material.dart';
8 9 10 11 12 13 14
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/painting.dart';

import '../rendering/mock_canvas.dart';

void main() {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  test('SliderThemeData copyWith, ==, hashCode basics', () {
    expect(const SliderThemeData(), const SliderThemeData().copyWith());
    expect(const SliderThemeData().hashCode, const SliderThemeData().copyWith().hashCode);
  });

  testWidgets('Default SliderThemeData debugFillProperties', (WidgetTester tester) async {
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    const SliderThemeData().debugFillProperties(builder);

    final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

    expect(description, <String>[]);
  });


  testWidgets('SliderThemeData implements debugFillProperties', (WidgetTester tester) async {
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    const SliderThemeData(
      trackHeight: 7.0,
      activeTrackColor: Color(0xFF000001),
      inactiveTrackColor: Color(0xFF000002),
      disabledActiveTrackColor: Color(0xFF000003),
      disabledInactiveTrackColor: Color(0xFF000004),
      activeTickMarkColor: Color(0xFF000005),
      inactiveTickMarkColor: Color(0xFF000006),
      disabledActiveTickMarkColor: Color(0xFF000007),
      disabledInactiveTickMarkColor: Color(0xFF000008),
      thumbColor: Color(0xFF000009),
      overlappingShapeStrokeColor: Color(0xFF000010),
      disabledThumbColor: Color(0xFF000011),
      overlayColor: Color(0xFF000012),
      valueIndicatorColor: Color(0xFF000013),
      overlayShape: RoundSliderOverlayShape(),
      tickMarkShape: RoundSliderTickMarkShape(),
      thumbShape: RoundSliderThumbShape(),
      trackShape: RoundedRectSliderTrackShape(),
      valueIndicatorShape: PaddleSliderValueIndicatorShape(),
      rangeTickMarkShape: RoundRangeSliderTickMarkShape(),
      rangeThumbShape: RoundRangeSliderThumbShape(),
      rangeTrackShape: RoundedRectRangeSliderTrackShape(),
      rangeValueIndicatorShape: PaddleRangeSliderValueIndicatorShape(),
      showValueIndicator: ShowValueIndicator.always,
      valueIndicatorTextStyle: TextStyle(color: Colors.black),
    ).debugFillProperties(builder);

    final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

    expect(description, <String>[
      'trackHeight: 7.0',
      'activeTrackColor: Color(0xff000001)',
      'inactiveTrackColor: Color(0xff000002)',
      'disabledActiveTrackColor: Color(0xff000003)',
      'disabledInactiveTrackColor: Color(0xff000004)',
      'activeTickMarkColor: Color(0xff000005)',
      'inactiveTickMarkColor: Color(0xff000006)',
      'disabledActiveTickMarkColor: Color(0xff000007)',
      'disabledInactiveTickMarkColor: Color(0xff000008)',
      'thumbColor: Color(0xff000009)',
      'overlappingShapeStrokeColor: Color(0xff000010)',
      'disabledThumbColor: Color(0xff000011)',
      'overlayColor: Color(0xff000012)',
      'valueIndicatorColor: Color(0xff000013)',
83 84 85 86 87 88 89 90 91
      "overlayShape: Instance of 'RoundSliderOverlayShape'",
      "tickMarkShape: Instance of 'RoundSliderTickMarkShape'",
      "thumbShape: Instance of 'RoundSliderThumbShape'",
      "trackShape: Instance of 'RoundedRectSliderTrackShape'",
      "valueIndicatorShape: Instance of 'PaddleSliderValueIndicatorShape'",
      "rangeTickMarkShape: Instance of 'RoundRangeSliderTickMarkShape'",
      "rangeThumbShape: Instance of 'RoundRangeSliderThumbShape'",
      "rangeTrackShape: Instance of 'RoundedRectRangeSliderTrackShape'",
      "rangeValueIndicatorShape: Instance of 'PaddleRangeSliderValueIndicatorShape'",
92
      'showValueIndicator: always',
93
      'valueIndicatorTextStyle: TextStyle(inherit: true, color: Color(0xff000000))',
94 95 96
    ]);
  });

97
  testWidgets('Slider uses ThemeData slider theme if present', (WidgetTester tester) async {
98
    final ThemeData theme = ThemeData(
99 100 101 102
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme;
103 104 105 106 107
    final SliderThemeData customTheme = sliderTheme.copyWith(
      activeTrackColor: Colors.purple,
      inactiveTrackColor: Colors.purple.withAlpha(0x3d),
    );

108
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false));
109
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
110 111

    expect(
112
      material,
113 114 115 116 117 118
      paints
        ..rrect(color: customTheme.disabledActiveTrackColor)
        ..rrect(color: customTheme.disabledInactiveTrackColor),
    );
  });

119
  testWidgets('Slider overrides ThemeData theme if SliderTheme present', (WidgetTester tester) async {
120
    final ThemeData theme = ThemeData(
121 122 123 124 125
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme;
    final SliderThemeData customTheme = sliderTheme.copyWith(
126 127
      activeTrackColor: Colors.purple,
      inactiveTrackColor: Colors.purple.withAlpha(0x3d),
128 129
    );

130
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false));
131
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
132

133
    expect(
134
      material,
135
      paints
136 137
        ..rrect(color: customTheme.disabledActiveTrackColor)
        ..rrect(color: customTheme.disabledInactiveTrackColor),
138
    );
139 140
  });

141
  testWidgets('SliderThemeData generates correct opacities for fromPrimaryColors', (WidgetTester tester) async {
142 143 144 145
    const Color customColor1 = Color(0xcafefeed);
    const Color customColor2 = Color(0xdeadbeef);
    const Color customColor3 = Color(0xdecaface);
    const Color customColor4 = Color(0xfeedcafe);
146

147
    final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
148 149 150
      primaryColor: customColor1,
      primaryColorDark: customColor2,
      primaryColorLight: customColor3,
151
      valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: customColor4),
152 153
    );

154 155 156 157
    expect(sliderTheme.activeTrackColor, equals(customColor1.withAlpha(0xff)));
    expect(sliderTheme.inactiveTrackColor, equals(customColor1.withAlpha(0x3d)));
    expect(sliderTheme.disabledActiveTrackColor, equals(customColor2.withAlpha(0x52)));
    expect(sliderTheme.disabledInactiveTrackColor, equals(customColor2.withAlpha(0x1f)));
158 159 160 161 162 163
    expect(sliderTheme.activeTickMarkColor, equals(customColor3.withAlpha(0x8a)));
    expect(sliderTheme.inactiveTickMarkColor, equals(customColor1.withAlpha(0x8a)));
    expect(sliderTheme.disabledActiveTickMarkColor, equals(customColor3.withAlpha(0x1f)));
    expect(sliderTheme.disabledInactiveTickMarkColor, equals(customColor2.withAlpha(0x1f)));
    expect(sliderTheme.thumbColor, equals(customColor1.withAlpha(0xff)));
    expect(sliderTheme.disabledThumbColor, equals(customColor2.withAlpha(0x52)));
164
    expect(sliderTheme.overlayColor, equals(customColor1.withAlpha(0x1f)));
165
    expect(sliderTheme.valueIndicatorColor, equals(customColor1.withAlpha(0xff)));
166
    expect(sliderTheme.valueIndicatorTextStyle!.color, equals(customColor4));
167 168
  });

169 170 171 172 173 174 175 176 177 178
  testWidgets('SliderThemeData generates correct shapes for fromPrimaryColors', (WidgetTester tester) async {
    const Color customColor1 = Color(0xcafefeed);
    const Color customColor2 = Color(0xdeadbeef);
    const Color customColor3 = Color(0xdecaface);
    const Color customColor4 = Color(0xfeedcafe);

    final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
      primaryColor: customColor1,
      primaryColorDark: customColor2,
      primaryColorLight: customColor3,
179
      valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: customColor4),
180 181 182 183 184 185 186 187 188 189 190 191 192
    );

    expect(sliderTheme.overlayShape, const RoundSliderOverlayShape());
    expect(sliderTheme.tickMarkShape, const RoundSliderTickMarkShape());
    expect(sliderTheme.thumbShape, const RoundSliderThumbShape());
    expect(sliderTheme.trackShape, const RoundedRectSliderTrackShape());
    expect(sliderTheme.valueIndicatorShape, const PaddleSliderValueIndicatorShape());
    expect(sliderTheme.rangeTickMarkShape, const RoundRangeSliderTickMarkShape());
    expect(sliderTheme.rangeThumbShape, const RoundRangeSliderThumbShape());
    expect(sliderTheme.rangeTrackShape, const RoundedRectRangeSliderTrackShape());
    expect(sliderTheme.rangeValueIndicatorShape, const PaddleRangeSliderValueIndicatorShape());
  });

193
  testWidgets('SliderThemeData lerps correctly', (WidgetTester tester) async {
194
    final SliderThemeData sliderThemeBlack = SliderThemeData.fromPrimaryColors(
195 196 197
      primaryColor: Colors.black,
      primaryColorDark: Colors.black,
      primaryColorLight: Colors.black,
198
      valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.black),
199
    ).copyWith(trackHeight: 2.0);
200
    final SliderThemeData sliderThemeWhite = SliderThemeData.fromPrimaryColors(
201 202 203
      primaryColor: Colors.white,
      primaryColorDark: Colors.white,
      primaryColorLight: Colors.white,
204
      valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.white),
205
    ).copyWith(trackHeight: 6.0);
206
    final SliderThemeData lerp = SliderThemeData.lerp(sliderThemeBlack, sliderThemeWhite, 0.5);
207
    const Color middleGrey = Color(0xff7f7f7f);
208 209

    expect(lerp.trackHeight, equals(4.0));
210 211 212 213
    expect(lerp.activeTrackColor, equals(middleGrey.withAlpha(0xff)));
    expect(lerp.inactiveTrackColor, equals(middleGrey.withAlpha(0x3d)));
    expect(lerp.disabledActiveTrackColor, equals(middleGrey.withAlpha(0x52)));
    expect(lerp.disabledInactiveTrackColor, equals(middleGrey.withAlpha(0x1f)));
214 215 216 217 218 219
    expect(lerp.activeTickMarkColor, equals(middleGrey.withAlpha(0x8a)));
    expect(lerp.inactiveTickMarkColor, equals(middleGrey.withAlpha(0x8a)));
    expect(lerp.disabledActiveTickMarkColor, equals(middleGrey.withAlpha(0x1f)));
    expect(lerp.disabledInactiveTickMarkColor, equals(middleGrey.withAlpha(0x1f)));
    expect(lerp.thumbColor, equals(middleGrey.withAlpha(0xff)));
    expect(lerp.disabledThumbColor, equals(middleGrey.withAlpha(0x52)));
220
    expect(lerp.overlayColor, equals(middleGrey.withAlpha(0x1f)));
221
    expect(lerp.valueIndicatorColor, equals(middleGrey.withAlpha(0xff)));
222
    expect(lerp.valueIndicatorTextStyle!.color, equals(middleGrey.withAlpha(0xff)));
223 224
  });

225
  testWidgets('Default slider track draws correctly', (WidgetTester tester) async {
226 227 228 229 230 231
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);

232
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
233
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
234 235 236 237 238 239 240

    const Radius radius = Radius.circular(2);
    const Radius activatedRadius = Radius.circular(3);

    // The enabled slider thumb has track segments that extend to and from
    // the center of the thumb.
    expect(
241
      material,
242 243 244 245 246
      paints
        ..rrect(rrect: RRect.fromLTRBAndCorners(24.0, 297.0, 212.0, 303.0, topLeft: activatedRadius, bottomLeft: activatedRadius), color: sliderTheme.activeTrackColor)
        ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 298.0, 776.0, 302.0, topRight: radius, bottomRight: radius), color: sliderTheme.inactiveTrackColor),
    );

247
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false));
248 249 250 251
    await tester.pumpAndSettle(); // wait for disable animation

    // The disabled slider thumb is the same size as the enabled thumb.
    expect(
252
      material,
253 254 255 256 257 258
      paints
        ..rrect(rrect: RRect.fromLTRBAndCorners(24.0, 297.0, 212.0, 303.0, topLeft: activatedRadius, bottomLeft: activatedRadius), color: sliderTheme.disabledActiveTrackColor)
        ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 298.0, 776.0, 302.0, topRight: radius, bottomRight: radius), color: sliderTheme.disabledInactiveTrackColor),
    );
  });

259 260 261 262 263 264 265
  testWidgets('Default slider overlay draws correctly', (WidgetTester tester) async {
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);

266
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
267
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
268 269 270

    // With no touch, paints only the thumb.
    expect(
271
      material,
272 273 274
      paints
        ..circle(
          color: sliderTheme.thumbColor,
275
          x: 212.0,
276
          y: 300.0,
277
          radius: 10.0,
278
        ),
279 280 281 282 283 284 285 286 287
    );

    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);
    // Wait for overlay animation to finish.
    await tester.pumpAndSettle();

    // After touch, paints thumb and overlay.
    expect(
288
      material,
289 290 291
      paints
        ..circle(
          color: sliderTheme.overlayColor,
292
          x: 212.0,
293
          y: 300.0,
294
          radius: 24.0,
295 296 297
        )
        ..circle(
          color: sliderTheme.thumbColor,
298
          x: 212.0,
299
          y: 300.0,
300
          radius: 10.0,
301
        ),
302 303 304 305
    );

    await gesture.up();
    await tester.pumpAndSettle();
306

307 308
    // After the gesture is up and complete, it again paints only the thumb.
    expect(
309
      material,
310 311 312
      paints
        ..circle(
          color: sliderTheme.thumbColor,
313
          x: 212.0,
314
          y: 300.0,
315
          radius: 10.0,
316
        ),
317 318 319 320
    );
  });

  testWidgets('Default slider ticker and thumb shape draw correctly', (WidgetTester tester) async {
321
    final ThemeData theme = ThemeData(
322 323 324 325 326
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);

327
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45));
328
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
329

330
    expect(material, paints..circle(color: sliderTheme.thumbColor, radius: 10.0));
331

332
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45, enabled: false));
333
    await tester.pumpAndSettle(); // wait for disable animation
334

335
    expect(material, paints..circle(color: sliderTheme.disabledThumbColor, radius: 10.0));
336

337 338 339
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45, divisions: 3));
    await tester.pumpAndSettle(); // wait for enable animation

340
    expect(
341
      material,
342 343 344 345 346
      paints
        ..circle(color: sliderTheme.activeTickMarkColor)
        ..circle(color: sliderTheme.activeTickMarkColor)
        ..circle(color: sliderTheme.inactiveTickMarkColor)
        ..circle(color: sliderTheme.inactiveTickMarkColor)
347
        ..circle(color: sliderTheme.thumbColor, radius: 10.0),
348
    );
349

350
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45, divisions: 3, enabled: false));
351
    await tester.pumpAndSettle(); // wait for disable animation
352

353
    expect(
354
      material,
355 356 357 358 359
      paints
        ..circle(color: sliderTheme.disabledActiveTickMarkColor)
        ..circle(color: sliderTheme.disabledInactiveTickMarkColor)
        ..circle(color: sliderTheme.disabledInactiveTickMarkColor)
        ..circle(color: sliderTheme.disabledInactiveTickMarkColor)
360
        ..circle(color: sliderTheme.disabledThumbColor, radius: 10.0),
361
    );
362 363
  });

364
  testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async {
Jose Alba's avatar
Jose Alba committed
365 366 367 368
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
369 370 371
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(
      thumbColor: Colors.red.shade500,
      showValueIndicator: ShowValueIndicator.always,
372
      valueIndicatorShape: const PaddleSliderValueIndicatorShape(),
373
    );
Jose Alba's avatar
Jose Alba committed
374
    Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) {
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
      return MaterialApp(
        home: Directionality(
          textDirection: TextDirection.ltr,
          child: MediaQuery(
            data: MediaQueryData.fromWindow(window).copyWith(textScaleFactor: textScale),
            child: Material(
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: SliderTheme(
                      data: sliderTheme,
                      child: Slider(
                        value: sliderValue,
                        label: value,
                        divisions: 3,
                        onChanged: (double d) { },
                      ),
Jose Alba's avatar
Jose Alba committed
392 393
                    ),
                  ),
394 395
                ],
              ),
Jose Alba's avatar
Jose Alba committed
396 397 398 399 400 401 402 403
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildApp('1'));

404
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
Jose Alba's avatar
Jose Alba committed
405 406 407 408 409 410

    Offset center = tester.getCenter(find.byType(Slider));
    TestGesture gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
411 412 413
      valueIndicatorBox,
      paints
        ..path(
414 415 416 417 418
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(15.9, -40.0),
            const Offset(-15.9, -40.0),
419
          ],
420
          excludes: <Offset>[const Offset(16.1, -40.0), const Offset(-16.1, -40.0)],
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
        ),
    );

    await gesture.up();

    // Test that it expands with a larger label.
    await tester.pumpWidget(buildApp('1000'));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..path(
436 437 438 439 440
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(35.9, -40.0),
            const Offset(-35.9, -40.0),
441
          ],
442
          excludes: <Offset>[const Offset(36.1, -40.0), const Offset(-36.1, -40.0)],
443 444 445 446 447 448 449 450 451 452 453 454 455 456
        ),
    );
    await gesture.up();

    // Test that it avoids the left edge of the screen.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..path(
457 458 459 460 461
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(92.0, -40.0),
            const Offset(-16.0, -40.0),
462
          ],
463 464
          excludes: <Offset>[const Offset(98.1, -40.0), const Offset(-20.1, -40.0)],
        ),
465 466 467 468 469 470 471 472 473 474 475 476 477
    );
    await gesture.up();

    // Test that it avoids the right edge of the screen.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 1.0));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..path(
478 479 480 481 482
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(16.0, -40.0),
            const Offset(-92.0, -40.0),
483
          ],
484 485
          excludes: <Offset>[const Offset(20.1, -40.0), const Offset(-98.1, -40.0)],
        ),
486 487 488
    );
    await gesture.up();

489
    // Test that the neck stretches when the text scale gets smaller.
490 491 492 493 494 495 496 497 498
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 0.5));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..path(
499 500 501 502 503
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -49.0),
            const Offset(68.0, -49.0),
            const Offset(-24.0, -49.0),
504
          ],
505 506 507 508 509
          excludes: <Offset>[
            const Offset(98.0, -32.0),  // inside full size, outside small
            const Offset(-40.0, -32.0),  // inside full size, outside small
            const Offset(90.1, -49.0),
            const Offset(-40.1, -49.0),
510
          ],
511
        ),
512 513 514
    );
    await gesture.up();

515 516
    // Test that the neck shrinks when the text scale gets larger.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.5));
517 518 519 520 521 522 523 524
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..path(
525 526 527 528 529 530
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -38.8),
            const Offset(92.0, -38.8),
            const Offset(8.0, -23.0), // Inside large, outside scale=1.0
            const Offset(-2.0, -23.0), // Inside large, outside scale=1.0
531
          ],
532 533 534 535 536
          excludes: <Offset>[
            const Offset(98.5, -38.8),
            const Offset(-16.1, -38.8),
          ],
        ),
537 538
    );
    await gesture.up();
539
  });
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580

  testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async {
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(
      thumbColor: Colors.red.shade500,
      showValueIndicator: ShowValueIndicator.always,
      valueIndicatorShape: const PaddleSliderValueIndicatorShape(),
    );
    Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) {
      return MaterialApp(
        home: Directionality(
          textDirection: TextDirection.ltr,
          child: MediaQuery(
            data: MediaQueryData.fromWindow(window).copyWith(textScaleFactor: textScale),
            child: Material(
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: SliderTheme(
                      data: sliderTheme,
                      child: Slider(
                        value: sliderValue,
                        label: value,
                        divisions: 3,
                        onChanged: (double d) { },
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildApp('1'));

581
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
582 583 584 585 586 587 588

    Offset center = tester.getCenter(find.byType(Slider));
    TestGesture gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
589 590 591 592 593 594 595 596 597
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(15.9, -40.0),
            const Offset(-15.9, -40.0),
          ],
          excludes: <Offset>[const Offset(16.1, -40.0), const Offset(-16.1, -40.0)],
598
        ),
599
    );
600 601 602 603 604 605 606 607

    await gesture.up();

    // Test that it expands with a larger label.
    await tester.pumpWidget(buildApp('1000'));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
608
    await tester.pumpAndSettle();
609
    expect(
610
      valueIndicatorBox,
611 612 613 614 615 616 617 618 619
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(35.9, -40.0),
            const Offset(-35.9, -40.0),
          ],
          excludes: <Offset>[const Offset(36.1, -40.0), const Offset(-36.1, -40.0)],
620
        ),
621
    );
622
    await gesture.up();
623 624 625 626 627 628

    // Test that it avoids the left edge of the screen.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
629
    await tester.pumpAndSettle();
630
    expect(
631
      valueIndicatorBox,
632 633 634 635 636
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
637
            const Offset(92.0, -40.0),
638 639
            const Offset(-16.0, -40.0),
          ],
640
          excludes: <Offset>[const Offset(98.1, -40.0), const Offset(-20.1, -40.0)],
641
        ),
642
    );
643 644 645 646 647 648 649
    await gesture.up();

    // Test that it avoids the right edge of the screen.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 1.0));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
650
    await tester.pumpAndSettle();
651
    expect(
652
      valueIndicatorBox,
653 654 655 656 657 658
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -40.0),
            const Offset(16.0, -40.0),
659
            const Offset(-92.0, -40.0),
660
          ],
661
          excludes: <Offset>[const Offset(20.1, -40.0), const Offset(-98.1, -40.0)],
662
        ),
663
    );
664
    await gesture.up();
665 666 667 668 669 670 671 672

    // Test that the neck stretches when the text scale gets smaller.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 0.5));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
673
      valueIndicatorBox,
674 675 676 677 678
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -49.0),
679
            const Offset(68.0, -49.0),
680 681 682 683
            const Offset(-24.0, -49.0),
          ],
          excludes: <Offset>[
            const Offset(98.0, -32.0),  // inside full size, outside small
684
            const Offset(-40.0, -32.0),  // inside full size, outside small
685
            const Offset(90.1, -49.0),
686
            const Offset(-40.1, -49.0),
687
          ],
688
        ),
689
    );
690 691 692 693 694 695 696 697 698
    await gesture.up();

    // Test that the neck shrinks when the text scale gets larger.
    await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.5));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
699
      valueIndicatorBox,
700 701 702 703 704
      paints
        ..path(
          color: sliderTheme.valueIndicatorColor,
          includes: <Offset>[
            const Offset(0.0, -38.8),
705 706 707
            const Offset(92.0, -38.8),
            const Offset(8.0, -23.0), // Inside large, outside scale=1.0
            const Offset(-2.0, -23.0), // Inside large, outside scale=1.0
708 709 710 711 712
          ],
          excludes: <Offset>[
            const Offset(98.5, -38.8),
            const Offset(-16.1, -38.8),
          ],
713
        ),
714
    );
715
    await gesture.up();
716
  });
717 718 719

  testWidgets('The slider track height can be overridden', (WidgetTester tester) async {
    final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(trackHeight: 16);
720 721 722
    const Radius radius = Radius.circular(8);
    const Radius activatedRadius = Radius.circular(9);

723
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
724

725
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
726 727 728

    // Top and bottom are centerY (300) + and - trackRadius (8).
    expect(
729
      material,
730 731 732 733 734
      paints
        ..rrect(rrect: RRect.fromLTRBAndCorners(24.0, 291.0, 212.0, 309.0, topLeft: activatedRadius, bottomLeft: activatedRadius), color: sliderTheme.activeTrackColor)
        ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 292.0, 776.0, 308.0, topRight: radius, bottomRight: radius), color: sliderTheme.inactiveTrackColor),
    );

735
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false));
736 737 738 739 740
    await tester.pumpAndSettle(); // wait for disable animation

    // The disabled thumb is smaller so the active track has to paint longer to
    // get to the edge.
    expect(
741
      material,
742 743 744 745 746 747
      paints
        ..rrect(rrect: RRect.fromLTRBAndCorners(24.0, 291.0, 212.0, 309.0, topLeft: activatedRadius, bottomLeft: activatedRadius), color: sliderTheme.disabledActiveTrackColor)
        ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 292.0, 776.0, 308.0, topRight: radius, bottomRight: radius), color: sliderTheme.disabledInactiveTrackColor),
    );
  });

748 749
  testWidgets('The default slider thumb shape sizes can be overridden', (WidgetTester tester) async {
    final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
750 751 752 753
      thumbShape: const RoundSliderThumbShape(
        enabledThumbRadius: 7,
        disabledThumbRadius: 11,
      ),
754 755 756
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
757
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
758 759

    expect(
760
      material,
761
      paints..circle(x: 212, y: 300, radius: 7, color: sliderTheme.thumbColor),
762 763 764 765 766 767
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false));
    await tester.pumpAndSettle(); // wait for disable animation

    expect(
768
      material,
769
      paints..circle(x: 212, y: 300, radius: 11, color: sliderTheme.disabledThumbColor),
770 771 772 773 774 775 776 777 778 779 780
    );
  });

  testWidgets('The default slider thumb shape disabled size can be inferred from the enabled size', (WidgetTester tester) async {
    final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
      thumbShape: const RoundSliderThumbShape(
        enabledThumbRadius: 9,
      ),
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
781
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
782 783

    expect(
784
      material,
785
      paints..circle(x: 212, y: 300, radius: 9, color: sliderTheme.thumbColor),
786 787 788 789 790
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false));
    await tester.pumpAndSettle(); // wait for disable animation
    expect(
791
      material,
792
      paints..circle(x: 212, y: 300, radius: 9, color: sliderTheme.disabledThumbColor),
793 794 795 796 797
    );
  });

  testWidgets('The default slider tick mark shape size can be overridden', (WidgetTester tester) async {
    final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
798
      tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 5),
799 800 801 802 803 804 805 806
      activeTickMarkColor: const Color(0xfadedead),
      inactiveTickMarkColor: const Color(0xfadebeef),
      disabledActiveTickMarkColor: const Color(0xfadecafe),
      disabledInactiveTickMarkColor: const Color(0xfadeface),
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2));

807
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
808

809
    expect(
810
      material,
811 812 813 814 815 816
      paints
        ..circle(x: 26, y: 300, radius: 5, color: sliderTheme.activeTickMarkColor)
        ..circle(x: 400, y: 300, radius: 5, color: sliderTheme.activeTickMarkColor)
        ..circle(x: 774, y: 300, radius: 5, color: sliderTheme.inactiveTickMarkColor),
    );

817
    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2,  enabled: false));
818 819 820
    await tester.pumpAndSettle();

    expect(
821
      material,
822 823 824 825 826 827 828
      paints
        ..circle(x: 26, y: 300, radius: 5, color: sliderTheme.disabledActiveTickMarkColor)
        ..circle(x: 400, y: 300, radius: 5, color: sliderTheme.disabledActiveTickMarkColor)
        ..circle(x: 774, y: 300, radius: 5, color: sliderTheme.disabledInactiveTickMarkColor),
    );
  });

829 830 831 832 833 834 835 836 837 838 839 840 841 842
  testWidgets('The default slider overlay shape size can be overridden', (WidgetTester tester) async {
    const double uniqueOverlayRadius = 23;
    final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
      overlayShape: const RoundSliderOverlayShape(
        overlayRadius: uniqueOverlayRadius,
      ),
    );

    await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5));
    // Tap center and wait for animation.
    final Offset center = tester.getCenter(find.byType(Slider));
    await tester.startGesture(center);
    await tester.pumpAndSettle();

843
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
844
    expect(
845
      material,
846 847 848 849 850
      paints..circle(
        x: center.dx,
        y: center.dy,
        radius: uniqueOverlayRadius,
        color: sliderTheme.overlayColor,
851
      ),
852 853
    );
  });
854 855 856 857 858 859 860 861

  // Only the thumb, overlay, and tick mark have special shortcuts to provide
  // no-op or empty shapes.
  //
  // The track can also be skipped by providing 0 height.
  //
  // The value indicator can be skipped by passing the appropriate
  // [ShowValueIndicator].
862
  testWidgets('The slider can skip all of its component painting', (WidgetTester tester) async {
863 864 865 866 867 868 869 870 871 872
    // Pump a slider with all shapes skipped.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.never,
      ),
      value: 0.5,
873
      divisions: 4,
874 875
    ));

876
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
877

878 879 880
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));
    expect(material, paintsExactlyCountTimes(#drawPath, 0));
881 882 883 884 885 886 887 888 889 890 891 892
  });

  testWidgets('The slider can skip all component painting except the track', (WidgetTester tester) async {
    // Pump a slider with just a track.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.never,
      ),
      value: 0.5,
893
      divisions: 4,
894 895
    ));

896
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
897 898

    // Only 2 track segments.
899
    expect(material, paintsExactlyCountTimes(#drawRRect, 2));
900 901
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));
    expect(material, paintsExactlyCountTimes(#drawPath, 0));
902 903 904 905 906 907 908 909 910 911
  });

  testWidgets('The slider can skip all component painting except the tick marks', (WidgetTester tester) async {
    // Pump a slider with just tick marks.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        showValueIndicator: ShowValueIndicator.never,
912 913 914
        // When the track is hidden to 0 height, a tick mark radius
        // must be provided to get a non-zero radius.
        tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 1),
915 916
      ),
      value: 0.5,
917
      divisions: 4,
918 919
    ));

920
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
921 922

    // Only 5 tick marks.
923 924 925
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 5));
    expect(material, paintsExactlyCountTimes(#drawPath, 0));
926 927 928 929 930 931 932 933 934 935 936 937
  });

  testWidgets('The slider can skip all component painting except the thumb', (WidgetTester tester) async {
    // Pump a slider with just a thumb.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.never,
      ),
      value: 0.5,
938
      divisions: 4,
939 940
    ));

941
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
942 943

    // Only 1 thumb.
944 945 946
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
    expect(material, paintsExactlyCountTimes(#drawPath, 0));
947 948 949 950 951 952 953 954 955 956 957 958
  });

  testWidgets('The slider can skip all component painting except the overlay', (WidgetTester tester) async {
    // Pump a slider with just an overlay.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.never,
      ),
      value: 0.5,
959
      divisions: 4,
960 961
    ));

962
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
963 964 965 966 967 968 969

    // Tap the center of the track and wait for animations to finish.
    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);
    await tester.pumpAndSettle();

    // Only 1 overlay.
970 971 972
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
    expect(material, paintsExactlyCountTimes(#drawPath, 0));
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987

    await gesture.up();
  });

  testWidgets('The slider can skip all component painting except the value indicator', (WidgetTester tester) async {
    // Pump a slider with just a value indicator.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.always,
      ),
      value: 0.5,
988
      divisions: 4,
989 990
    ));

991
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
992
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
993 994 995 996 997 998 999

    // Tap the center of the track and wait for animations to finish.
    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);
    await tester.pumpAndSettle();

    // Only 1 value indicator.
1000 1001
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));
1002
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));
Jose Alba's avatar
Jose Alba committed
1003 1004 1005 1006

    await gesture.up();
  });

1007
  testWidgets('PaddleSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async {
Jose Alba's avatar
Jose Alba committed
1008 1009 1010 1011 1012 1013 1014 1015
    // Pump a slider with just a value indicator.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.always,
1016
        valueIndicatorShape: const PaddleSliderValueIndicatorShape(),
Jose Alba's avatar
Jose Alba committed
1017 1018 1019 1020 1021
      ),
      value: 0.5,
      divisions: 4,
    ));

1022
    final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
1023
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
Jose Alba's avatar
Jose Alba committed
1024 1025 1026 1027 1028 1029 1030

    // Tap the center of the track to kick off the animation of the value indicator.
    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);

    // Nothing to paint at scale 0.
    await tester.pump();
1031 1032
    expect(material, paintsExactlyCountTimes(#drawRect, 0));
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));
1033
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));
Jose Alba's avatar
Jose Alba committed
1034 1035 1036

    // Painting a path for the value indicator.
    await tester.pump(const Duration(milliseconds: 16));
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));

    await gesture.up();
  });

  testWidgets('Default slider value indicator shape skips all painting at zero scale', (WidgetTester tester) async {
    // Pump a slider with just a value indicator.
    await tester.pumpWidget(_buildApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.always,
      ),
      value: 0.5,
      divisions: 4,
    ));

1056
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

    // Tap the center of the track to kick off the animation of the value indicator.
    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);

    // Nothing to paint at scale 0.
    await tester.pump();
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));

    // Painting a path for the value indicator.
    await tester.pump(const Duration(milliseconds: 16));
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));

    await gesture.up();
  });

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086

  testWidgets('Default paddle range slider value indicator shape draws correctly', (WidgetTester tester) async {
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(
      thumbColor: Colors.red.shade500,
      showValueIndicator: ShowValueIndicator.always,
      rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(),
    );

    await tester.pumpWidget(_buildRangeApp(sliderTheme));

1087
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121

    final Offset center = tester.getCenter(find.byType(RangeSlider));
    final TestGesture gesture = await tester.startGesture(center);
    // Wait for value indicator animation to finish.
    await tester.pumpAndSettle();
    expect(
      valueIndicatorBox,
      paints
        ..rrect(rrect: RRect.fromLTRBAndCorners(
          24.0, 298.0, 24.0, 302.0,
          topLeft: const Radius.circular(2.0),
          topRight: const Radius.circular(0.0),
          bottomRight: const Radius.circular(0.0),
          bottomLeft: const Radius.circular(2.0),
        ))
        ..rect(rect: const Rect.fromLTRB(24.0, 297.0, 24.0, 303.0))
        ..rrect(rrect: RRect.fromLTRBAndCorners(
          24.0, 298.0, 776.0, 302.0,
          topLeft: const Radius.circular(0.0),
          topRight: const Radius.circular(2.0),
          bottomRight: const Radius.circular(2.0),
          bottomLeft: const Radius.circular(0.0),
        ))
        ..circle(x: 24.0, y: 300.0)
        ..shadow(elevation: 1.0)
        ..circle(x: 24.0, y: 300.0)
        ..shadow(elevation: 6.0)
        ..circle(x: 24.0, y: 300.0)
    );

    await gesture.up();

  });

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
  testWidgets('PaddleRangeSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async {
    // Pump a slider with just a value indicator.
    await tester.pumpWidget(_buildRangeApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(),
      ),
      values: const RangeValues(0, 0.5),
      divisions: 4,
    ));

//    final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
1134
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164

    // Tap the center of the track to kick off the animation of the value indicator.
    final Offset center = tester.getCenter(find.byType(RangeSlider));
    final TestGesture gesture = await tester.startGesture(center);

    // No value indicator path to paint at scale 0.
    await tester.pump();
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));

    // Painting a path for each value indicator.
    await tester.pump(const Duration(milliseconds: 16));
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2));

    await gesture.up();
  });

  testWidgets('Default range indicator shape skips all painting at zero scale', (WidgetTester tester) async {
    // Pump a slider with just a value indicator.
    await tester.pumpWidget(_buildRangeApp(
      ThemeData().sliderTheme.copyWith(
        trackHeight: 0,
        overlayShape: SliderComponentShape.noOverlay,
        thumbShape: SliderComponentShape.noThumb,
        tickMarkShape: SliderTickMarkShape.noTickMark,
        showValueIndicator: ShowValueIndicator.always,
      ),
      values: const RangeValues(0, 0.5),
      divisions: 4,
    ));

1165
    final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177

    // Tap the center of the track to kick off the animation of the value indicator.
    final Offset center = tester.getCenter(find.byType(RangeSlider));
    final TestGesture gesture = await tester.startGesture(center);

    // No value indicator path to paint at scale 0.
    await tester.pump();
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));

    // Painting a path for each value indicator.
    await tester.pump(const Duration(milliseconds: 16));
    expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2));
1178 1179 1180 1181

    await gesture.up();
  });
}
1182

1183
Widget _buildApp(
1184 1185 1186
    SliderThemeData sliderTheme, {
      double value = 0.0,
      bool enabled = true,
1187
      int? divisions,
1188
    }) {
1189
  final ValueChanged<double>? onChanged = enabled ? (double d) => value = d : null;
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
  return MaterialApp(
    home: Scaffold(
      body: Center(
        child: SliderTheme(
          data: sliderTheme,
          child: Slider(
            value: value,
            label: '$value',
            onChanged: onChanged,
            divisions: divisions,
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
          ),
        ),
      ),
    ),
  );
}

Widget _buildRangeApp(
    SliderThemeData sliderTheme, {
      RangeValues values = const RangeValues(0, 0),
      bool enabled = true,
1211
      int? divisions,
1212
    }) {
1213
  final ValueChanged<RangeValues>? onChanged = enabled ? (RangeValues d) => values = d : null;
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
  return MaterialApp(
    home: Scaffold(
      body: Center(
        child: SliderTheme(
          data: sliderTheme,
          child: RangeSlider(
            values: values,
            labels: RangeLabels(values.start.toString(), values.end.toString()),
            onChanged: onChanged,
            divisions: divisions,
1224 1225 1226 1227 1228
          ),
        ),
      ),
    ),
  );
1229
}