back_button_test.dart 965 Bytes
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: new Material(child: const Text('Home')),
13 14 15
        routes: <String, WidgetBuilder>{
          '/next': (BuildContext context) {
            return new 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 35

    expect(find.text('Home'), findsOneWidget);
  });
}