diff --git a/examples/flutter_gallery/flutter_gallery.iml b/examples/flutter_gallery/flutter_gallery.iml index 3a913c2a72..984d8a6e78 100644 --- a/examples/flutter_gallery/flutter_gallery.iml +++ b/examples/flutter_gallery/flutter_gallery.iml @@ -3,6 +3,7 @@ + diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index b493b10a65..1c47f1814b 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; import 'dart:developer' as developer; import 'dart:ui' as ui show window; import 'dart:ui' show AppLifecycleState, Locale; @@ -59,6 +60,8 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren ui.window.onLocaleChanged = handleLocaleChanged; ui.window.onPopRoute = handlePopRoute; ui.window.onAppLifecycleStateChanged = handleAppLifecycleStateChanged; + PlatformMessages.setJSONMessageHandler('flutter/navigation', _handleNavigationMessage); + PlatformMessages.setStringMessageHandler('flutter/lifecycle', _handleLifecycleMessage); } /// The current [WidgetsBinding], if one has been created. @@ -157,8 +160,6 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren /// [WidgetsApp] uses this in conjunction with a [Navigator] to /// cause the back button to close dialog boxes, return from modal /// pages, and so forth. - /// - /// See [ui.window.onPopRoute]. void handlePopRoute() { for (WidgetsBindingObserver observer in _observers) { if (observer.didPopRoute()) @@ -167,17 +168,34 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren SystemNavigator.pop(); } + Future _handleNavigationMessage(Map message) async { + final String method = message['method']; + if (method == 'popRoute') + handlePopRoute(); + // TODO(abarth): Handle 'pushRoute'. + } + /// Called when the application lifecycle state changes. /// /// Notifies all the observers using /// [WidgetsBindingObserver.didChangeAppLifecycleState]. - /// - /// See [ui.window.onAppLifecycleStateChanged]. void handleAppLifecycleStateChanged(AppLifecycleState state) { for (WidgetsBindingObserver observer in _observers) observer.didChangeAppLifecycleState(state); } + Future _handleLifecycleMessage(String message) async { + switch (message) { + case 'AppLifecycleState.paused': + handleAppLifecycleStateChanged(AppLifecycleState.paused); + break; + case 'AppLifecycleState.resumed': + handleAppLifecycleStateChanged(AppLifecycleState.resumed); + break; + } + return null; + } + bool _needToReportFirstFrame = true; bool _thisFrameWasUseful = true;