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

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'navigator.dart';

/// Messages for route change notifications.
class RouteNotificationMessages {
12 13 14
  // This class is not meant to be instatiated or extended; this constructor
  // prevents instantiation and extension.
  // ignore: unused_element
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  RouteNotificationMessages._();

  /// When the engine is Web notify the platform for a route change.
  static void maybeNotifyRouteChange(String methodName, Route<dynamic> route, Route<dynamic> previousRoute) {
    if(kIsWeb) {
      _notifyRouteChange(methodName, route, previousRoute);
    } else {
      // No op.
    }
  }

  /// Notifies the platform of a route change.
  ///
  /// There are three methods: 'routePushed', 'routePopped', 'routeReplaced'.
  ///
30 31 32 33
  /// See also:
  ///
  ///  * [SystemChannels.navigation], which handles subsequent navigation
  ///    requests.
34 35 36
  static void _notifyRouteChange(String methodName, Route<dynamic> route, Route<dynamic> previousRoute) {
    final String previousRouteName = previousRoute?.settings?.name;
    final String routeName = route?.settings?.name;
37 38 39 40 41 42 43
    SystemChannels.navigation.invokeMethod<void>(
      methodName,
      <String, dynamic>{
        'previousRouteName': previousRouteName,
        'routeName': routeName,
      },
    );
44 45
  }
}