diff --git a/lib/themes/material_demo_theme_data.dart b/lib/themes/material_demo_theme_data.dart index 6c33c5b901..ec7651a651 100644 --- a/lib/themes/material_demo_theme_data.dart +++ b/lib/themes/material_demo_theme_data.dart @@ -7,29 +7,54 @@ import 'package:flutter/material.dart'; class MaterialDemoThemeData { static final themeData = ThemeData( - colorScheme: _colorScheme, - appBarTheme: AppBarTheme( - color: _colorScheme.primary, - iconTheme: IconThemeData(color: _colorScheme.onPrimary), - ), - bottomAppBarTheme: BottomAppBarTheme( - color: _colorScheme.primary, - ), - canvasColor: _colorScheme.background, - toggleableActiveColor: _colorScheme.primary, - highlightColor: Colors.transparent, - indicatorColor: _colorScheme.onPrimary, - primaryColor: _colorScheme.primary, - backgroundColor: Colors.white, - scaffoldBackgroundColor: _colorScheme.background, - snackBarTheme: const SnackBarThemeData( - behavior: SnackBarBehavior.floating, - ), - typography: Typography.material2018( - platform: defaultTargetPlatform, - ), - visualDensity: VisualDensity.standard, - ); + colorScheme: _colorScheme, + canvasColor: _colorScheme.background, + highlightColor: Colors.transparent, + indicatorColor: _colorScheme.onPrimary, + primaryColor: _colorScheme.primary, + backgroundColor: Colors.white, + scaffoldBackgroundColor: _colorScheme.background, + typography: Typography.material2018( + platform: defaultTargetPlatform, + ), + visualDensity: VisualDensity.standard, + // Component themes + appBarTheme: AppBarTheme( + color: _colorScheme.primary, + iconTheme: IconThemeData(color: _colorScheme.onPrimary), + ), + bottomAppBarTheme: BottomAppBarTheme( + color: _colorScheme.primary, + ), + checkboxTheme: CheckboxThemeData( + fillColor: MaterialStateProperty.resolveWith((states) { + return states.contains(MaterialState.selected) + ? _colorScheme.primary + : null; + }), + ), + radioTheme: RadioThemeData( + fillColor: MaterialStateProperty.resolveWith((states) { + return states.contains(MaterialState.selected) + ? _colorScheme.primary + : null; + }), + ), + snackBarTheme: const SnackBarThemeData( + behavior: SnackBarBehavior.floating, + ), + switchTheme: SwitchThemeData( + thumbColor: MaterialStateProperty.resolveWith((states) { + return states.contains(MaterialState.selected) + ? _colorScheme.primary + : null; + }), + trackColor: MaterialStateProperty.resolveWith((states) { + return states.contains(MaterialState.selected) + ? _colorScheme.primary + : null; + }), + )); static const _colorScheme = ColorScheme( primary: Color(0xFF6200EE), diff --git a/test/theme_test.dart b/test/theme_test.dart new file mode 100644 index 0000000000..84c25fcee3 --- /dev/null +++ b/test/theme_test.dart @@ -0,0 +1,31 @@ +// Copyright 2019 The Flutter team. 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:gallery/themes/material_demo_theme_data.dart'; +import 'package:test/test.dart'; + +void main() { + test('verify former toggleableActiveColor themes are set', () async { + const Color primaryColor = Color(0xFF6200EE); + final ThemeData themeData = MaterialDemoThemeData.themeData; + + expect( + themeData.checkboxTheme.fillColor!.resolve({MaterialState.selected}), + primaryColor, + ); + expect( + themeData.radioTheme.fillColor!.resolve({MaterialState.selected}), + primaryColor, + ); + expect( + themeData.switchTheme.thumbColor!.resolve({MaterialState.selected}), + primaryColor, + ); + expect( + themeData.switchTheme.trackColor!.resolve({MaterialState.selected}), + primaryColor, + ); + }); +}