Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Migrate ThemeData.toggleableActiveColor (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piinks authored May 24, 2022
1 parent 4299f7c commit 15df50c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 23 deletions.
71 changes: 48 additions & 23 deletions lib/themes/material_demo_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Color?>((states) {
return states.contains(MaterialState.selected)
? _colorScheme.primary
: null;
}),
),
radioTheme: RadioThemeData(
fillColor: MaterialStateProperty.resolveWith<Color?>((states) {
return states.contains(MaterialState.selected)
? _colorScheme.primary
: null;
}),
),
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
switchTheme: SwitchThemeData(
thumbColor: MaterialStateProperty.resolveWith<Color?>((states) {
return states.contains(MaterialState.selected)
? _colorScheme.primary
: null;
}),
trackColor: MaterialStateProperty.resolveWith<Color?>((states) {
return states.contains(MaterialState.selected)
? _colorScheme.primary
: null;
}),
));

static const _colorScheme = ColorScheme(
primary: Color(0xFF6200EE),
Expand Down
31 changes: 31 additions & 0 deletions test/theme_test.dart
Original file line number Diff line number Diff line change
@@ -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,
);
});
}

0 comments on commit 15df50c

Please sign in to comment.