card.2_test.dart 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// 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(0xfffffbfe));
    expect(defaultCard.shadowColor, const Color(0xff000000));
    expect(defaultCard.surfaceTintColor, const Color(0xff6750a4));

    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(0xffe7e0ec));
    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(0xfffffbfe));
    expect(outlinedCard.shadowColor, const Color(0xff000000));
    expect(outlinedCard.surfaceTintColor, const Color(0xff6750a4));
  });
}