flutter/examples/api/test/material/card/card.2_test.dart
Qun Cheng a2c7ed95d1
Introduce tone-based surfaces and accent color add-ons - Part 2 (#138521)
This PR is to introduce 19 new color roles and deprecate 3 color roles in `ColorScheme`.
**Tone-based surface colors** (7 colors): 
* surfaceBright
* surfaceDim
* surfaceContainer
* surfaceContainerLowest
* surfaceContainerLow
* surfaceContainerHigh
* surfaceContainerHighest

**Accent color add-ons** (12 colors):
* primary/secondary/tertiary-Fixed
* primary/secondary/tertiary-FixedDim
* onPrimary/onSecondary/onTertiary-Fixed
* onPrimary/onSecondary/onTertiary-FixedVariant

**Deprecated colors**:
* background -> replaced with surface
* onBackground -> replaced with onSurface
* surfaceVariant -> replaced with surfaceContainerHighest

Please checkout this [design doc](https://docs.google.com/document/d/1ODqivpM_6c490T4j5XIiWCDKo5YqHy78YEFqDm4S8h4/edit?usp=sharing) for more information:)

![Screenshot 2024-01-08 at 4 56 51 PM](https://github.com/flutter/flutter/assets/36861262/353cdb4c-6ba9-4435-a518-fd3f67e415f0)
2024-02-20 19:01:50 +00:00

60 lines
2.4 KiB
Dart

// Copyright 2014 The Flutter 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_api_samples/material/card/card.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Card variants', (WidgetTester tester) async {
await tester.pumpWidget(const example.CardExamplesApp());
expect(find.byType(Card), findsNWidgets(3));
expect(find.widgetWithText(Card, 'Elevated Card'), findsOneWidget);
expect(find.widgetWithText(Card, 'Filled Card'), findsOneWidget);
expect(find.widgetWithText(Card, 'Outlined Card'), findsOneWidget);
Material getCardMaterial(WidgetTester tester, int cardIndex) {
return tester.widget<Material>(
find.descendant(
of: find.byType(Card).at(cardIndex),
matching: find.byType(Material),
),
);
}
final Material defaultCard = getCardMaterial(tester, 0);
expect(defaultCard.clipBehavior, Clip.none);
expect(defaultCard.elevation, 1.0);
expect(defaultCard.shape, const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(defaultCard.color, const Color(0xfff7f2fa));
expect(defaultCard.shadowColor, const Color(0xff000000));
expect(defaultCard.surfaceTintColor, Colors.transparent);
final Material filledCard = getCardMaterial(tester, 1);
expect(filledCard.clipBehavior, Clip.none);
expect(filledCard.elevation, 0.0);
expect(filledCard.shape, const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(filledCard.color, const Color(0xffe6e0e9));
expect(filledCard.shadowColor, const Color(0xff000000));
expect(filledCard.surfaceTintColor, const Color(0x00000000));
final Material outlinedCard = getCardMaterial(tester, 2);
expect(outlinedCard.clipBehavior, Clip.none);
expect(outlinedCard.elevation, 0.0);
expect(outlinedCard.shape, const RoundedRectangleBorder(
side: BorderSide(color: Color(0xffcac4d0)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(outlinedCard.color, const Color(0xfffef7ff));
expect(outlinedCard.shadowColor, const Color(0xff000000));
expect(outlinedCard.surfaceTintColor, Colors.transparent);
});
}