app_navigator_key_test.dart 1.22 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:flutter/widgets.dart';
9

10
final RouteFactory generateRoute = (RouteSettings settings) => PageRouteBuilder<void>(
11 12 13 14 15 16 17 18
  settings: settings,
  pageBuilder: (BuildContext context, Animation<double> animation1, Animation<double> animation2) {
    return const Placeholder();
  },
);

void main() {
  testWidgets('WidgetsApp.navigatorKey', (WidgetTester tester) async {
19 20
    final GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>();
    await tester.pumpWidget(WidgetsApp(
21 22 23 24
      navigatorKey: key,
      color: const Color(0xFF112233),
      onGenerateRoute: generateRoute,
    ));
Dan Field's avatar
Dan Field committed
25
    expect(key.currentState, isA<NavigatorState>());
26
    await tester.pumpWidget(WidgetsApp(
27 28 29 30
      color: const Color(0xFF112233),
      onGenerateRoute: generateRoute,
    ));
    expect(key.currentState, isNull);
31
    await tester.pumpWidget(WidgetsApp(
32 33 34 35
      navigatorKey: key,
      color: const Color(0xFF112233),
      onGenerateRoute: generateRoute,
    ));
Dan Field's avatar
Dan Field committed
36
    expect(key.currentState, isA<NavigatorState>());
37 38
  });
}