felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
389 stars 63 forks source link

fix: don't lose system push route events and pass them to WidgetsBindings #42

Closed orestesgaolin closed 3 years ago

orestesgaolin commented 3 years ago

Status

READY

Breaking Changes

NO

Description

Before this change any system push intents e.g. with new deep links would be lost on Android. This was happening when app was running in the background and new deep link was received. Now if there's any information about the deep link route, it will be passed to WidgetsBinding so that all subscribers would be able to handle it (RouterDelegate, MaterialApp, custom implementors of WidgetsBinding).

Sample implementation of custom handler:

class CustomHandler with WidgetsBindingObserver {
  CustomHandler(WidgetsBinding widgetsBinding)
      : _widgetsBinding = widgetsBinding,
        assert(widgetsBinding != null) {
    _widgetsBinding.addObserver(this);
  }

  final WidgetsBinding _widgetsBinding;

  /// Must be called when the `MaterialApp` is initialized
  /// in order to fetch the initial route.
  ///
  /// The initial route cannot be fetched before the
  /// `MaterialApp` is built for the first time.
  void initialize() {
    final route = _widgetsBinding.window.defaultRouteName;
    if (route != null) {
      // handle
    }
  }

  @override
  Future<bool> didPushRouteInformation(
      RouteInformation routeInformation) async {
    // handle
    return true;
  }

  @override
  Future<bool> didPushRoute(String route) async {
    // handle
    return true;
  }

  /// Disposes subscribing to WidgetsBinding events
  void dispose() {
    _widgetsBinding.removeObserver(this);
  }
}

Type of Change