slider_test.dart 47.3 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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';

7
import 'package:flutter/foundation.dart';
8
import 'package:flutter/material.dart';
9
import 'package:flutter/rendering.dart';
10 11 12
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';

13
import '../rendering/mock_canvas.dart';
14
import '../widgets/semantics_tester.dart';
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29
// A thumb shape that also logs its repaint center.
class LoggingThumbShape extends SliderComponentShape {
  LoggingThumbShape(this.log);

  final List<Offset> log;

  @override
  Size getPreferredSize(bool isEnabled, bool isDiscrete) {
    return const Size(10.0, 10.0);
  }

  @override
  void paint(
    PaintingContext context,
30
    Offset thumbCenter, {
31 32
    Animation<double> activationAnimation,
    Animation<double> enableAnimation,
33
    bool isDiscrete,
34
    TextPainter labelPainter,
35
    RenderBox parentBox,
36 37 38
    SliderThemeData sliderTheme,
    TextDirection textDirection,
    double value,
39
  }) {
40 41 42 43 44 45
    log.add(thumbCenter);
    final Paint thumbPaint = new Paint()..color = Colors.red;
    context.canvas.drawCircle(thumbCenter, 5.0, thumbPaint);
  }
}

46
void main() {
47
  testWidgets('Slider can move when tapped (LTR)', (WidgetTester tester) async {
48
    final Key sliderKey = new UniqueKey();
49
    double value = 0.0;
50 51
    double startValue;
    double endValue;
52

53
    await tester.pumpWidget(
54 55 56 57
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
58 59 60 61 62 63 64 65 66 67 68 69
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    onChanged: (double newValue) {
                      setState(() {
                        value = newValue;
                      });
                    },
70 71 72 73 74 75
                    onChangeStart: (double value) {
                      startValue = value;
                    },
                    onChangeEnd: (double value) {
                      endValue = value;
                    },
76
                  ),
77
                ),
78
              ),
79 80 81
            );
          },
        ),
82
      ),
83
    );
84

85
    expect(value, equals(0.0));
86
    await tester.tap(find.byKey(sliderKey));
87
    expect(value, equals(0.5));
88 89 90 91
    expect(startValue, equals(0.0));
    expect(endValue, equals(0.5));
    startValue = null;
    endValue = null;
92
    await tester.pump(); // No animation should start.
93
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
94 95 96 97 98 99 100

    final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey));
    final Offset bottomRight = tester.getBottomRight(find.byKey(sliderKey));

    final Offset target = topLeft + (bottomRight - topLeft) / 4.0;
    await tester.tapAt(target);
    expect(value, closeTo(0.25, 0.05));
101 102
    expect(startValue, equals(0.5));
    expect(endValue, closeTo(0.25, 0.05));
103 104
    await tester.pump(); // No animation should start.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
105 106
  });

107
  testWidgets('Slider can move when tapped (RTL)', (WidgetTester tester) async {
108
    final Key sliderKey = new UniqueKey();
109
    double value = 0.0;
110

111
    await tester.pumpWidget(
112 113 114 115
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
116 117 118 119 120 121 122 123 124 125 126 127 128
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    onChanged: (double newValue) {
                      setState(() {
                        value = newValue;
                      });
                    },
                  ),
129
                ),
130
              ),
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
            );
          },
        ),
      ),
    );

    expect(value, equals(0.0));
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
    await tester.pump(); // No animation should start.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));

    final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey));
    final Offset bottomRight = tester.getBottomRight(find.byKey(sliderKey));

    final Offset target = topLeft + (bottomRight - topLeft) / 4.0;
    await tester.tapAt(target);
    expect(value, closeTo(0.75, 0.05));
    await tester.pump(); // No animation should start.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
  });

153
  testWidgets("Slider doesn't send duplicate change events if tapped on the same value", (WidgetTester tester) async {
154 155
    final Key sliderKey = new UniqueKey();
    double value = 0.0;
156 157
    double startValue;
    double endValue;
158
    int updates = 0;
159 160
    int startValueUpdates = 0;
    int endValueUpdates = 0;
161 162 163 164 165 166

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
167 168 169 170
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
171 172 173 174 175
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    onChanged: (double newValue) {
                      setState(() {
176
                        updates++;
177 178 179
                        value = newValue;
                      });
                    },
180 181 182 183 184 185 186 187
                    onChangeStart: (double value) {
                      startValueUpdates++;
                      startValue = value;
                    },
                    onChangeEnd: (double value) {
                      endValueUpdates++;
                      endValue = value;
                    },
188 189 190 191 192 193
                  ),
                ),
              ),
            );
          },
        ),
194
      ),
195
    );
196

197 198 199
    expect(value, equals(0.0));
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
200 201
    expect(startValue, equals(0.0));
    expect(endValue, equals(0.5));
202 203 204 205 206
    await tester.pump();
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
    await tester.pump();
    expect(updates, equals(1));
207 208
    expect(startValueUpdates, equals(2));
    expect(endValueUpdates, equals(2));
209 210
  });

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
  testWidgets('Value indicator shows for a bit after being tapped', (WidgetTester tester) async {
    final Key sliderKey = new UniqueKey();
    double value = 0.0;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    divisions: 4,
                    onChanged: (double newValue) {
                      setState(() {
                        value = newValue;
                      });
                    },
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

    expect(value, equals(0.0));
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
    await tester.pump(const Duration(milliseconds: 100));
    // Starts with the position animation and value indicator
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump(const Duration(milliseconds: 100));
    // Value indicator is longer than position.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
    await tester.pump(const Duration(milliseconds: 100));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
    await tester.pump(const Duration(milliseconds: 100));
    // Shown for long enough, value indicator is animated closed.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
    await tester.pump(const Duration(milliseconds: 101));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
  });

  testWidgets('Discrete Slider repaints and animates when dragged', (WidgetTester tester) async {
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    final Key sliderKey = new UniqueKey();
    double value = 0.0;
    final List<Offset> log = <Offset>[];
    final LoggingThumbShape loggingThumb = new LoggingThumbShape(log);
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            final SliderThemeData sliderTheme = SliderTheme.of(context).copyWith(thumbShape: loggingThumb);
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new SliderTheme(
                    data: sliderTheme,
                    child: new Slider(
                      key: sliderKey,
                      value: value,
                      divisions: 4,
                      onChanged: (double newValue) {
                        setState(() {
                          value = newValue;
                        });
                      },
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

    final List<Offset> expectedLog = <Offset>[
      const Offset(16.0, 300.0),
      const Offset(16.0, 300.0),
      const Offset(400.0, 300.0),
    ];
    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(sliderKey)));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 100));
    expect(value, equals(0.5));
    expect(log.length, 3);
    expect(log, orderedEquals(expectedLog));
    await gesture.moveBy(const Offset(-500.0, 0.0));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 10));
    expect(value, equals(0.0));
    expect(log.length, 5);
314 315 316 317 318 319 320
    expect(log.last.dx, closeTo(386.3, 0.1));
    // With no more gesture or value changes, the thumb position should still
    // be redrawn in the animated position.
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 10));
    expect(value, equals(0.0));
    expect(log.length, 7);
321
    expect(log.last.dx, closeTo(343.3, 0.1));
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    // Final position.
    await tester.pump(const Duration(milliseconds: 80));
    expectedLog.add(const Offset(16.0, 300.0));
    expect(value, equals(0.0));
    expect(log.length, 8);
    expect(log.last.dx, closeTo(16.0, 0.1));
    await gesture.up();
  });

  testWidgets("Slider doesn't send duplicate change events if tapped on the same value", (WidgetTester tester) async {
    final Key sliderKey = new UniqueKey();
    double value = 0.0;
    int updates = 0;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    onChanged: (double newValue) {
                      setState(() {
                        updates++;
                        value = newValue;
                      });
                    },
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

    expect(value, equals(0.0));
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
    await tester.pump();
    await tester.tap(find.byKey(sliderKey));
    expect(value, equals(0.5));
    await tester.pump();
    expect(updates, equals(1));
  });

  testWidgets('discrete Slider repaints when dragged', (WidgetTester tester) async {
    final Key sliderKey = new UniqueKey();
    double value = 0.0;
    final List<Offset> log = <Offset>[];
    final LoggingThumbShape loggingThumb = new LoggingThumbShape(log);
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            final SliderThemeData sliderTheme = SliderTheme.of(context).copyWith(thumbShape: loggingThumb);
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new SliderTheme(
                    data: sliderTheme,
                    child: new Slider(
                      key: sliderKey,
                      value: value,
                      divisions: 4,
                      onChanged: (double newValue) {
                        setState(() {
                          value = newValue;
                        });
                      },
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

    final List<Offset> expectedLog = <Offset>[
      const Offset(16.0, 300.0),
      const Offset(16.0, 300.0),
      const Offset(400.0, 300.0),
    ];
    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(sliderKey)));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 100));
    expect(value, equals(0.5));
    expect(log.length, 3);
    expect(log, orderedEquals(expectedLog));
    await gesture.moveBy(const Offset(-500.0, 0.0));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 10));
    expect(value, equals(0.0));
    expect(log.length, 5);
    expect(log.last.dx, closeTo(386.3, 0.1));
426 427 428 429 430 431
    // With no more gesture or value changes, the thumb position should still
    // be redrawn in the animated position.
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 10));
    expect(value, equals(0.0));
    expect(log.length, 7);
432
    expect(log.last.dx, closeTo(343.3, 0.1));
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    // Final position.
    await tester.pump(const Duration(milliseconds: 80));
    expectedLog.add(const Offset(16.0, 300.0));
    expect(value, equals(0.0));
    expect(log.length, 8);
    expect(log.last.dx, closeTo(16.0, 0.1));
    await gesture.up();
  });

  testWidgets('Slider take on discrete values', (WidgetTester tester) async {
    final Key sliderKey = new UniqueKey();
    double value = 0.0;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new SizedBox(
                    width: 144.0 + 2 * 16.0, // _kPreferredTotalWidth
                    child: new Slider(
                      key: sliderKey,
                      min: 0.0,
                      max: 100.0,
                      divisions: 10,
                      value: value,
                      onChanged: (double newValue) {
                        setState(() {
                          value = newValue;
                        });
                      },
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

478
    expect(value, equals(0.0));
479
    await tester.tap(find.byKey(sliderKey));
480
    expect(value, equals(50.0));
481
    await tester.drag(find.byKey(sliderKey), const Offset(5.0, 0.0));
482
    expect(value, equals(50.0));
483
    await tester.drag(find.byKey(sliderKey), const Offset(40.0, 0.0));
484
    expect(value, equals(80.0));
485

486
    await tester.pump(); // Starts animation.
487
    expect(SchedulerBinding.instance.transientCallbackCount, greaterThan(0));
488 489 490 491
    await tester.pump(const Duration(milliseconds: 200));
    await tester.pump(const Duration(milliseconds: 200));
    await tester.pump(const Duration(milliseconds: 200));
    await tester.pump(const Duration(milliseconds: 200));
492 493
    // Animation complete.
    expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
494
  });
495

496
  testWidgets('Slider can be given zero values', (WidgetTester tester) async {
497
    final List<double> log = <double>[];
498 499
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
500 501 502 503 504 505 506 507 508 509 510
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Slider(
            value: 0.0,
            min: 0.0,
            max: 1.0,
            onChanged: (double newValue) {
              log.add(newValue);
            },
          ),
511
        ),
512 513 514 515 516 517 518
      ),
    ));

    await tester.tap(find.byType(Slider));
    expect(log, <double>[0.5]);
    log.clear();

519 520
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
521 522 523 524 525 526 527 528 529 530 531
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Slider(
            value: 0.0,
            min: 0.0,
            max: 0.0,
            onChanged: (double newValue) {
              log.add(newValue);
            },
          ),
532
        ),
533 534 535 536 537 538 539
      ),
    ));

    await tester.tap(find.byType(Slider));
    expect(log, <double>[]);
    log.clear();
  });
540

541
  testWidgets('Slider uses the right theme colors for the right components', (WidgetTester tester) async {
542 543
    const Color customColor1 = Color(0xcafefeed);
    const Color customColor2 = Color(0xdeadbeef);
544 545 546 547 548 549 550 551 552 553
    final ThemeData theme = new ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    final SliderThemeData sliderTheme = theme.sliderTheme;
    double value = 0.45;
    Widget buildApp({
      Color activeColor,
      Color inactiveColor,
      int divisions,
554
      bool enabled = true,
555 556 557 558 559 560
    }) {
      final ValueChanged<double> onChanged = !enabled
          ? null
          : (double d) {
              value = d;
            };
561 562
      return new Directionality(
        textDirection: TextDirection.ltr,
563 564 565 566 567 568 569 570 571 572 573 574 575 576
        child: new MediaQuery(
          data: new MediaQueryData.fromWindow(window),
          child: new Material(
            child: new Center(
              child: new Theme(
                data: theme,
                child: new Slider(
                  value: value,
                  label: '$value',
                  divisions: divisions,
                  activeColor: activeColor,
                  inactiveColor: inactiveColor,
                  onChanged: onChanged,
                ),
577
              ),
578 579 580 581 582 583
            ),
          ),
        ),
      );
    }

584
    await tester.pumpWidget(buildApp());
585

586
    final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider));
587

588
    // Check default theme for enabled widget.
589
    expect(sliderBox, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: sliderTheme.inactiveTrackColor));
590 591
    expect(sliderBox, paints..circle(color: sliderTheme.thumbColor));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
592 593
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
594 595 596 597 598
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.activeTickMarkColor)));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor)));

    // Test setting only the activeColor.
    await tester.pumpWidget(buildApp(activeColor: customColor1));
599
    expect(sliderBox, paints..rect(color: customColor1)..rect(color: sliderTheme.inactiveTrackColor));
600 601 602
    expect(sliderBox, paints..circle(color: customColor1));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
603 604
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
605 606 607

    // Test setting only the inactiveColor.
    await tester.pumpWidget(buildApp(inactiveColor: customColor1));
608
    expect(sliderBox, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: customColor1));
609 610
    expect(sliderBox, paints..circle(color: sliderTheme.thumbColor));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
611 612
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
613 614 615 616 617 618 619

    // Test setting both activeColor and inactiveColor.
    await tester.pumpWidget(buildApp(activeColor: customColor1, inactiveColor: customColor2));
    expect(sliderBox, paints..rect(color: customColor1)..rect(color: customColor2));
    expect(sliderBox, paints..circle(color: customColor1));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
620 621
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
622 623 624

    // Test colors for discrete slider.
    await tester.pumpWidget(buildApp(divisions: 3));
625
    expect(sliderBox, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: sliderTheme.inactiveTrackColor));
626 627 628 629 630 631 632 633 634
    expect(
        sliderBox,
        paints
          ..circle(color: sliderTheme.activeTickMarkColor)
          ..circle(color: sliderTheme.activeTickMarkColor)
          ..circle(color: sliderTheme.inactiveTickMarkColor)
          ..circle(color: sliderTheme.inactiveTickMarkColor)
          ..circle(color: sliderTheme.thumbColor));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
635 636
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
637 638

    // Test colors for discrete slider with inactiveColor and activeColor set.
639 640 641 642 643
    await tester.pumpWidget(buildApp(
      activeColor: customColor1,
      inactiveColor: customColor2,
      divisions: 3,
    ));
644 645 646 647 648 649 650 651 652 653 654
    expect(sliderBox, paints..rect(color: customColor1)..rect(color: customColor2));
    expect(
        sliderBox,
        paints
          ..circle(color: customColor2)
          ..circle(color: customColor2)
          ..circle(color: customColor1)
          ..circle(color: customColor1)
          ..circle(color: customColor1));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
655 656
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor)));
657 658 659 660 661
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.activeTickMarkColor)));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor)));

    // Test default theme for disabled widget.
    await tester.pumpWidget(buildApp(enabled: false));
662
    await tester.pumpAndSettle();
663 664 665
    expect(
        sliderBox,
        paints
666 667
          ..rect(color: sliderTheme.disabledActiveTrackColor)
          ..rect(color: sliderTheme.disabledInactiveTrackColor));
668 669
    expect(sliderBox, paints..circle(color: sliderTheme.disabledThumbColor));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
670 671
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor)));
672 673

    // Test setting the activeColor and inactiveColor for disabled widget.
674
    await tester.pumpWidget(buildApp(activeColor: customColor1, inactiveColor: customColor2, enabled: false));
675 676 677
    expect(
        sliderBox,
        paints
678 679
          ..rect(color: sliderTheme.disabledActiveTrackColor)
          ..rect(color: sliderTheme.disabledInactiveTrackColor));
680 681
    expect(sliderBox, paints..circle(color: sliderTheme.disabledThumbColor));
    expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
682 683
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor)));
    expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor)));
684 685 686 687 688

    // Test that the default value indicator has the right colors.
    await tester.pumpWidget(buildApp(divisions: 3));
    Offset center = tester.getCenter(find.byType(Slider));
    TestGesture gesture = await tester.startGesture(center);
689
    // Wait for value indicator animation to finish.
690
    await tester.pumpAndSettle();
691 692 693 694
    expect(value, equals(2.0 / 3.0));
    expect(
      sliderBox,
      paints
695 696
        ..rect(color: sliderTheme.activeTrackColor)
        ..rect(color: sliderTheme.inactiveTrackColor)
697 698 699 700 701 702 703 704 705
        ..circle(color: sliderTheme.overlayColor)
        ..circle(color: sliderTheme.activeTickMarkColor)
        ..circle(color: sliderTheme.activeTickMarkColor)
        ..circle(color: sliderTheme.inactiveTickMarkColor)
        ..circle(color: sliderTheme.inactiveTickMarkColor)
        ..path(color: sliderTheme.valueIndicatorColor)
        ..circle(color: sliderTheme.thumbColor),
    );
    await gesture.up();
706
    // Wait for value indicator animation to finish.
707
    await tester.pumpAndSettle();
708 709 710 711 712 713 714 715 716

    // Testing the custom colors are used for the indicator.
    await tester.pumpWidget(buildApp(
      divisions: 3,
      activeColor: customColor1,
      inactiveColor: customColor2,
    ));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
717
    // Wait for value indicator animation to finish.
718
    await tester.pumpAndSettle();
719 720 721 722 723 724 725 726 727 728 729 730 731 732
    expect(value, equals(2.0 / 3.0));
    expect(
      sliderBox,
      paints
        ..rect(color: customColor1)
        ..rect(color: customColor2)
        ..circle(color: customColor1.withAlpha(0x29))
        ..circle(color: customColor2)
        ..circle(color: customColor2)
        ..circle(color: customColor1)
        ..path(color: customColor1)
        ..circle(color: customColor1),
    );
    await gesture.up();
733
  });
734

735
  testWidgets('Slider can tap in vertical scroller', (WidgetTester tester) async {
736
    double value = 0.0;
737 738
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new ListView(
            children: <Widget>[
              new Slider(
                value: value,
                onChanged: (double newValue) {
                  value = newValue;
                },
              ),
              new Container(
                height: 2000.0,
              ),
            ],
          ),
755 756 757 758 759 760 761 762 763 764 765 766
        ),
      ),
    ));

    await tester.tap(find.byType(Slider));
    expect(value, equals(0.5));
  });

  testWidgets('Slider drags immediately (LTR)', (WidgetTester tester) async {
    double value = 0.0;
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
767 768 769 770 771 772 773 774 775 776
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Center(
            child: new Slider(
              value: value,
              onChanged: (double newValue) {
                value = newValue;
              },
            ),
777
          ),
778
        ),
779 780 781
      ),
    ));

782 783 784
    final Offset center = tester.getCenter(find.byType(Slider));
    final TestGesture gesture = await tester.startGesture(center);

785
    expect(value, equals(0.5));
786 787 788 789 790 791

    await gesture.moveBy(const Offset(1.0, 0.0));

    expect(value, greaterThan(0.5));

    await gesture.up();
792 793
  });

794
  testWidgets('Slider drags immediately (RTL)', (WidgetTester tester) async {
795
    double value = 0.0;
796 797
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.rtl,
798 799 800 801 802 803 804 805 806 807
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Center(
            child: new Slider(
              value: value,
              onChanged: (double newValue) {
                value = newValue;
              },
            ),
808
          ),
809 810 811 812
        ),
      ),
    ));

813
    final Offset center = tester.getCenter(find.byType(Slider));
814
    final TestGesture gesture = await tester.startGesture(center);
815 816 817

    expect(value, equals(0.5));

818
    await gesture.moveBy(const Offset(1.0, 0.0));
819

820
    expect(value, lessThan(0.5));
821 822 823

    await gesture.up();
  });
824 825

  testWidgets('Slider sizing', (WidgetTester tester) async {
826
    await tester.pumpWidget(new Directionality(
827
      textDirection: TextDirection.ltr,
828 829 830
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: const Material(
831 832
          child: Center(
            child: Slider(
833 834 835
              value: 0.5,
              onChanged: null,
            ),
836
          ),
837 838 839 840 841
        ),
      ),
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Slider)).size, const Size(800.0, 600.0));

842
    await tester.pumpWidget(new Directionality(
843
      textDirection: TextDirection.ltr,
844 845 846
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: const Material(
847 848 849
          child: Center(
            child: IntrinsicWidth(
              child: Slider(
850 851 852
                value: 0.5,
                onChanged: null,
              ),
853
            ),
854 855 856 857
          ),
        ),
      ),
    ));
858
    expect(tester.renderObject<RenderBox>(find.byType(Slider)).size, const Size(144.0 + 2.0 * 16.0, 600.0));
859

860
    await tester.pumpWidget(new Directionality(
861
      textDirection: TextDirection.ltr,
862 863 864
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: const Material(
865 866
          child: Center(
            child: OverflowBox(
867 868
              maxWidth: double.infinity,
              maxHeight: double.infinity,
869
              child: Slider(
870 871 872
                value: 0.5,
                onChanged: null,
              ),
873
            ),
874 875 876 877
          ),
        ),
      ),
    ));
878
    expect(tester.renderObject<RenderBox>(find.byType(Slider)).size, const Size(144.0 + 2.0 * 16.0, 32.0));
879
  });
880

881
  testWidgets('Slider respects textScaleFactor', (WidgetTester tester) async {
882 883 884
    final Key sliderKey = new UniqueKey();
    double value = 0.0;

885 886
    Widget buildSlider({
      double textScaleFactor,
887 888
      bool isDiscrete = true,
      ShowValueIndicator show = ShowValueIndicator.onlyForDiscrete,
889
    }) {
890 891 892 893 894 895 896
      return new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData(textScaleFactor: textScaleFactor),
              child: new Material(
897 898
                child: new Theme(
                  data: Theme.of(context).copyWith(
899 900
                        sliderTheme: Theme.of(context).sliderTheme.copyWith(showValueIndicator: show),
                      ),
901 902
                  child: new Center(
                    child: new OverflowBox(
903 904
                      maxWidth: double.infinity,
                      maxHeight: double.infinity,
905 906 907 908 909 910 911 912 913 914 915 916 917
                      child: new Slider(
                        key: sliderKey,
                        min: 0.0,
                        max: 100.0,
                        divisions: isDiscrete ? 10 : null,
                        label: '${value.round()}',
                        value: value,
                        onChanged: (double newValue) {
                          setState(() {
                            value = newValue;
                          });
                        },
                      ),
918 919 920 921 922 923 924 925 926 927 928 929 930
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      );
    }

    await tester.pumpWidget(buildSlider(textScaleFactor: 1.0));
    Offset center = tester.getCenter(find.byType(Slider));
    TestGesture gesture = await tester.startGesture(center);
931
    await tester.pumpAndSettle();
932

933
    expect(tester.renderObject(find.byType(Slider)), paints..scale(x: 1.0, y: 1.0));
934 935

    await gesture.up();
936
    await tester.pumpAndSettle();
937 938 939 940

    await tester.pumpWidget(buildSlider(textScaleFactor: 2.0));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
941
    await tester.pumpAndSettle();
942

943 944 945
    expect(tester.renderObject(find.byType(Slider)), paints..scale(x: 2.0, y: 2.0));

    await gesture.up();
946
    await tester.pumpAndSettle();
947 948 949 950 951 952 953 954 955

    // Check continuous
    await tester.pumpWidget(buildSlider(
      textScaleFactor: 1.0,
      isDiscrete: false,
      show: ShowValueIndicator.onlyForContinuous,
    ));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
956
    await tester.pumpAndSettle();
957 958 959 960

    expect(tester.renderObject(find.byType(Slider)), paints..scale(x: 1.0, y: 1.0));

    await gesture.up();
961
    await tester.pumpAndSettle();
962 963 964 965 966 967 968 969

    await tester.pumpWidget(buildSlider(
      textScaleFactor: 2.0,
      isDiscrete: false,
      show: ShowValueIndicator.onlyForContinuous,
    ));
    center = tester.getCenter(find.byType(Slider));
    gesture = await tester.startGesture(center);
970
    await tester.pumpAndSettle();
971 972

    expect(tester.renderObject(find.byType(Slider)), paints..scale(x: 2.0, y: 2.0));
973 974

    await gesture.up();
975
    await tester.pumpAndSettle();
976 977
  });

978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
  testWidgets('Slider has correct animations when reparented', (WidgetTester tester) async {
    final Key sliderKey = new GlobalKey(debugLabel: 'A');
    double value = 0.0;

    Widget buildSlider(int parents) {
      Widget createParents(int parents, StateSetter setState) {
        Widget slider = new Slider(
          key: sliderKey,
          value: value,
          divisions: 4,
          onChanged: (double newValue) {
            setState(() {
              value = newValue;
            });
          },
        );

        for (int i = 0; i < parents; ++i) {
          slider = new Column(children: <Widget>[slider]);
        }
        return slider;
      }

      return new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: createParents(parents, setState),
              ),
            );
          },
        ),
      );
    }

    Future<Null> testReparenting(bool reparent) async {
      final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider));
      final Offset center = tester.getCenter(find.byType(Slider));
      // Move to 0.0.
      TestGesture gesture = await tester.startGesture(Offset.zero);
      await tester.pump();
      await gesture.up();
1023
      await tester.pumpAndSettle();
1024 1025 1026 1027 1028 1029 1030 1031
      expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
      expect(
        sliderBox,
        paints
          ..circle(x: 208.5, y: 16.0, radius: 1.0)
          ..circle(x: 400.0, y: 16.0, radius: 1.0)
          ..circle(x: 591.5, y: 16.0, radius: 1.0)
          ..circle(x: 783.0, y: 16.0, radius: 1.0)
1032
          ..circle(x: 16.0, y: 16.0, radius: 6.0),
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
      );

      gesture = await tester.startGesture(center);
      await tester.pump();
      // Wait for animations to start.
      await tester.pump(const Duration(milliseconds: 25));
      expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
      expect(
        sliderBox,
        paints
1043
          ..circle(x: 105.0625, y: 16.0, radius: 3.791776657104492)
1044 1045 1046 1047 1048
          ..circle(x: 17.0, y: 16.0, radius: 1.0)
          ..circle(x: 208.5, y: 16.0, radius: 1.0)
          ..circle(x: 400.0, y: 16.0, radius: 1.0)
          ..circle(x: 591.5, y: 16.0, radius: 1.0)
          ..circle(x: 783.0, y: 16.0, radius: 1.0)
1049
          ..circle(x: 105.0625, y: 16.0, radius: 6.0),
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
      );

      // Reparenting in the middle of an animation should do nothing.
      if (reparent) {
        await tester.pumpWidget(buildSlider(2));
      }

      // Move a little further in the animations.
      await tester.pump(const Duration(milliseconds: 10));
      expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
      expect(
        sliderBox,
        paints
1063
          ..circle(x: 185.5457763671875, y: 16.0, radius: 8.0)
1064 1065
          ..circle(x: 17.0, y: 16.0, radius: 1.0)
          ..circle(x: 208.5, y: 16.0, radius: 1.0)
1066
          ..circle(x: 400.0, y: 16.0, radius: 1.0)
1067 1068
          ..circle(x: 591.5, y: 16.0, radius: 1.0)
          ..circle(x: 783.0, y: 16.0, radius: 1.0)
1069
          ..circle(x: 185.5457763671875, y: 16.0, radius: 6.0),
1070 1071
      );
      // Wait for animations to finish.
1072
      await tester.pumpAndSettle();
1073 1074 1075 1076 1077 1078 1079 1080 1081
      expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
      expect(
        sliderBox,
        paints
          ..circle(x: 400.0, y: 16.0, radius: 16.0)
          ..circle(x: 17.0, y: 16.0, radius: 1.0)
          ..circle(x: 208.5, y: 16.0, radius: 1.0)
          ..circle(x: 591.5, y: 16.0, radius: 1.0)
          ..circle(x: 783.0, y: 16.0, radius: 1.0)
1082
          ..circle(x: 400.0, y: 16.0, radius: 6.0),
1083 1084
      );
      await gesture.up();
1085
      await tester.pumpAndSettle();
1086 1087 1088 1089 1090 1091 1092 1093
      expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
      expect(
        sliderBox,
        paints
          ..circle(x: 17.0, y: 16.0, radius: 1.0)
          ..circle(x: 208.5, y: 16.0, radius: 1.0)
          ..circle(x: 591.5, y: 16.0, radius: 1.0)
          ..circle(x: 783.0, y: 16.0, radius: 1.0)
1094
          ..circle(x: 400.0, y: 16.0, radius: 6.0),
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
      );
    }

    await tester.pumpWidget(buildSlider(1));
    // Do it once without reparenting in the middle of an animation
    await testReparenting(false);
    // Now do it again with reparenting in the middle of an animation.
    await testReparenting(true);
  });

1105 1106 1107
  testWidgets('Slider Semantics', (WidgetTester tester) async {
    final SemanticsTester semantics = new SemanticsTester(tester);

1108 1109
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
1110 1111 1112 1113 1114 1115 1116
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Slider(
            value: 0.5,
            onChanged: (double v) {},
          ),
1117 1118
        ),
      ),
1119
    ));
1120

1121 1122 1123 1124
    expect(
        semantics,
        hasSemantics(
          new TestSemantics.root(children: <TestSemantics>[
1125 1126
            new TestSemantics.rootChild(
              id: 1,
1127 1128 1129 1130
              value: '50%',
              increasedValue: '55%',
              decreasedValue: '45%',
              textDirection: TextDirection.ltr,
1131 1132
              actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
            ),
1133 1134 1135 1136
          ]),
          ignoreRect: true,
          ignoreTransform: true,
        ));
1137 1138

    // Disable slider
1139
    await tester.pumpWidget(new Directionality(
1140
      textDirection: TextDirection.ltr,
1141 1142 1143
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: const Material(
1144
          child: Slider(
1145 1146 1147
            value: 0.5,
            onChanged: null,
          ),
1148 1149
        ),
      ),
1150
    ));
1151

1152 1153 1154 1155 1156 1157 1158
    expect(
        semantics,
        hasSemantics(
          new TestSemantics.root(),
          ignoreRect: true,
          ignoreTransform: true,
        ));
1159 1160 1161

    semantics.dispose();
  });
1162

1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
  testWidgets('Slider Semantics - iOS', (WidgetTester tester) async {
    final SemanticsTester semantics = new SemanticsTester(tester);

    await tester.pumpWidget(
      new Theme(
        data: ThemeData.light().copyWith(
          platform: TargetPlatform.iOS,
        ),
        child: new Directionality(
          textDirection: TextDirection.ltr,
          child: new MediaQuery(
            data: new MediaQueryData.fromWindow(window),
            child: new Material(
              child: new Slider(
                value: 100.0,
                min: 0.0,
                max: 200.0,
                onChanged: (double v) {},
              ),
            ),
          ),
        ),
      ),
    );

    expect(
      semantics,
      hasSemantics(
        new TestSemantics.root(children: <TestSemantics>[
          new TestSemantics.rootChild(
            id: 2,
            value: '50%',
            increasedValue: '60%',
            decreasedValue: '40%',
            textDirection: TextDirection.ltr,
            actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
          ),
        ]),
        ignoreRect: true,
        ignoreTransform: true,
      ));
    semantics.dispose();
  });

  testWidgets('Slider semantics with custom formatter', (WidgetTester tester) async {
    final SemanticsTester semantics = new SemanticsTester(tester);

    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new MediaQuery(
        data: new MediaQueryData.fromWindow(window),
        child: new Material(
          child: new Slider(
            value: 40.0,
            min: 0.0,
            max: 200.0,
            divisions: 10,
            semanticFormatterCallback: (double value) => value.round().toString(),
            onChanged: (double v) {},
          ),
        ),
      ),
    ));

    expect(
        semantics,
        hasSemantics(
          new TestSemantics.root(children: <TestSemantics>[
            new TestSemantics.rootChild(
              id: 3,
              value: '40',
              increasedValue: '60',
              decreasedValue: '20',
              textDirection: TextDirection.ltr,
              actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
            ),
          ]),
          ignoreRect: true,
          ignoreTransform: true,
        ));
    semantics.dispose();
  });

1246 1247 1248 1249 1250 1251 1252
  testWidgets('Value indicator appears when it should', (WidgetTester tester) async {
    final ThemeData baseTheme = new ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
    SliderThemeData theme = baseTheme.sliderTheme;
    double value = 0.45;
1253
    Widget buildApp({SliderThemeData sliderTheme, int divisions, bool enabled = true}) {
1254 1255 1256
      final ValueChanged<double> onChanged = enabled ? (double d) => value = d : null;
      return new Directionality(
        textDirection: TextDirection.ltr,
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
        child: new MediaQuery(
          data: new MediaQueryData.fromWindow(window),
          child: new Material(
            child: new Center(
              child: new Theme(
                data: baseTheme,
                child: new SliderTheme(
                  data: sliderTheme,
                  child: new Slider(
                    value: value,
                    label: '$value',
                    divisions: divisions,
                    onChanged: onChanged,
                  ),
1271 1272 1273 1274 1275 1276 1277 1278
                ),
              ),
            ),
          ),
        ),
      );
    }

1279 1280 1281 1282
    Future<Null> expectValueIndicator({
      bool isVisible,
      SliderThemeData theme,
      int divisions,
1283
      bool enabled = true,
1284 1285
    }) async {
      // Discrete enabled widget.
1286 1287 1288
      await tester.pumpWidget(buildApp(sliderTheme: theme, divisions: divisions, enabled: enabled));
      final Offset center = tester.getCenter(find.byType(Slider));
      final TestGesture gesture = await tester.startGesture(center);
1289
      // Wait for value indicator animation to finish.
1290
      await tester.pumpAndSettle();
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328

      final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider));
      expect(
        sliderBox,
        isVisible
            ? (paints..path(color: theme.valueIndicatorColor))
            : isNot(paints..path(color: theme.valueIndicatorColor)),
      );
      await gesture.up();
    }

    // Default (showValueIndicator set to onlyForDiscrete).
    await expectValueIndicator(isVisible: true, theme: theme, divisions: 3, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: false);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: false);

    // With showValueIndicator set to onlyForContinuous.
    theme = theme.copyWith(showValueIndicator: ShowValueIndicator.onlyForContinuous);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: false);
    await expectValueIndicator(isVisible: true, theme: theme, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: false);

    // discrete enabled widget with showValueIndicator set to always.
    theme = theme.copyWith(showValueIndicator: ShowValueIndicator.always);
    await expectValueIndicator(isVisible: true, theme: theme, divisions: 3, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: false);
    await expectValueIndicator(isVisible: true, theme: theme, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: false);

    // discrete enabled widget with showValueIndicator set to never.
    theme = theme.copyWith(showValueIndicator: ShowValueIndicator.never);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, divisions: 3, enabled: false);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: true);
    await expectValueIndicator(isVisible: false, theme: theme, enabled: false);
  });
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369

  testWidgets("Slider doesn't start any animations after dispose", (WidgetTester tester) async {
    final Key sliderKey = new UniqueKey();
    double value = 0.0;
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return new MediaQuery(
              data: new MediaQueryData.fromWindow(window),
              child: new Material(
                child: new Center(
                  child: new Slider(
                    key: sliderKey,
                    value: value,
                    divisions: 4,
                    onChanged: (double newValue) {
                      setState(() {
                        value = newValue;
                      });
                    },
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(sliderKey)));
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
    expect(value, equals(0.5));
    await gesture.moveBy(const Offset(-500.0, 0.0));
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
    // Change the tree to dispose the original widget.
    await tester.pumpWidget(new Container());
    expect(await tester.pumpAndSettle(const Duration(milliseconds: 100)), equals(1));
    await gesture.up();
  });
1370
}