From 8d545e9301cc71517cf8ecff13823449c263f0d3 Mon Sep 17 00:00:00 2001 From: jslavitz Date: Tue, 9 Oct 2018 13:43:15 -0700 Subject: [PATCH] Add disabledThumbColor and other properties from Switch to SwitchListTile final (#22823) * added missing properties --- .../lib/src/material/switch_list_tile.dart | 21 +++++++ .../test/material/switch_list_tile_test.dart | 61 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 packages/flutter/test/material/switch_list_tile_test.dart diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 08130a3082..db1b1f2d31 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -74,6 +74,9 @@ class SwitchListTile extends StatelessWidget { @required this.value, @required this.onChanged, this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, this.activeThumbImage, this.inactiveThumbImage, this.title, @@ -123,6 +126,21 @@ class SwitchListTile extends StatelessWidget { /// Defaults to accent color of the current [Theme]. final Color activeColor; + /// The color to use on the track when this switch is on. + /// + /// Defaults to [ThemeData.toggleableActiveColor] with the opacity set at 50%. + final Color activeTrackColor; + + /// The color to use on the thumb when this switch is off. + /// + /// Defaults to the colors described in the Material design specification. + final Color inactiveThumbColor; + + /// The color to use on the track when this switch is off. + /// + /// Defaults to the colors described in the Material design specification. + final Color inactiveTrackColor; + /// An image to use on the thumb of this switch when the switch is on. final ImageProvider activeThumbImage; @@ -173,6 +191,9 @@ class SwitchListTile extends StatelessWidget { activeThumbImage: activeThumbImage, inactiveThumbImage: inactiveThumbImage, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + activeTrackColor: activeTrackColor, + inactiveTrackColor: inactiveTrackColor, + inactiveThumbColor: inactiveThumbColor, ); return MergeSemantics( child: ListTileTheme.merge( diff --git a/packages/flutter/test/material/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart new file mode 100644 index 0000000000..1a019dba08 --- /dev/null +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -0,0 +1,61 @@ +// Copyright 2018 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. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import '../rendering/mock_canvas.dart'; + +void main() { + testWidgets('SwitchListTile has the right colors', (WidgetTester tester) async { + bool value = false; + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(padding: EdgeInsets.all(8.0)), + child: Directionality( + textDirection: TextDirection.ltr, + child: + StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Material( + child: SwitchListTile( + value: value, + onChanged: (bool newValue) { + setState(() { value = newValue; }); + }, + activeColor: Colors.red[500], + activeTrackColor: Colors.green[500], + inactiveThumbColor: Colors.yellow[500], + inactiveTrackColor: Colors.blue[500], + ), + ); + }, + ), + ), + ), + ); + + expect( + find.byType(Switch), + paints + ..rrect(color: Colors.blue[500]) + ..circle(color: const Color(0x33000000)) + ..circle(color: const Color(0x24000000)) + ..circle(color: const Color(0x1f000000)) + ..circle(color: Colors.yellow[500]) + ); + + await tester.tap(find.byType(Switch)); + await tester.pumpAndSettle(); + + expect( + Material.of(tester.element(find.byType(Switch))), + paints + ..rrect(color: Colors.green[500]) + ..circle(color: const Color(0x33000000)) + ..circle(color: const Color(0x24000000)) + ..circle(color: const Color(0x1f000000)) + ..circle(color: Colors.red[500]) + ); + }); +}