back_button_test.dart 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2016 The Chromium 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_test/flutter_test.dart';

void main() {
  testWidgets('BackButton control test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
12
        home: const Material(child: const Text('Home')),
13 14
        routes: <String, WidgetBuilder>{
          '/next': (BuildContext context) {
15
            return const Material(
16
              child: const Center(
17 18 19 20 21 22 23 24 25 26
                child: const BackButton(),
              )
            );
          },
        }
      )
    );

    tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');

27
    await tester.pumpAndSettle();
28 29 30

    await tester.tap(find.byType(BackButton));

31
    await tester.pumpAndSettle();
32 33 34

    expect(find.text('Home'), findsOneWidget);
  });
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 60 61

  testWidgets('BackButton icon', (WidgetTester tester) async {
    final Key iOSKey = new UniqueKey();
    final Key androidKey = new UniqueKey();


    await tester.pumpWidget(
      new MaterialApp(
        home: new Column(
          children: <Widget>[
            new Theme(
              data: new ThemeData(platform: TargetPlatform.iOS),
              child: new BackButtonIcon(key: iOSKey),
            ),
            new Theme(
              data: new ThemeData(platform: TargetPlatform.android),
              child: new BackButtonIcon(key: androidKey),
            ),
          ],
        ),
      ),
    );

    final Icon iOSIcon = tester.widget(find.descendant(of: find.byKey(iOSKey), matching: find.byType(Icon)));
    final Icon androidIcon = tester.widget(find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon)));
    expect(iOSIcon == androidIcon, false);
  });
62
}