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

Migrate ThemeData.toggleableActiveColor #694

Merged
merged 6 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could you sort and keep the component themes together?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it, so nice. Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right? I almost want to propose a ThemeData ordering lint.

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,
);
});
}