Skip to content

A cross-platform plugin for managing redirect-based flows, like for OAuth Authorization code flow, payment gateways, etc...

License

Notifications You must be signed in to change notification settings

Bdaya-Dev/redirect

Repository files navigation

redirect logo

redirect

A cross-platform Dart & Flutter plugin for redirect-based flows.

License: MIT pub.dev style: very good analysis


What is redirect?

redirect opens a URL, waits for a callback redirect, and returns the result — all in a single, cross-platform API. It handles popup blockers on web, Custom Tabs on Android, ASWebAuthenticationSession on Apple platforms, and loopback HTTP servers on desktop.

import 'package:redirect/redirect.dart';

final handle = runRedirect(
  url: Uri.parse('https://example.com/start?...'),
  callbackUrlScheme: 'myapp',
);

final result = await handle.result;

switch (result) {
  case RedirectSuccess(:final uri):
    final code = uri.queryParameters['code'];
    // Handle the callback
  case RedirectCancelled():
    print('User cancelled');
  case RedirectFailure(:final error):
    print('Error: $error');
}

Platform Support

Platform Implementation Mechanism
Android redirect_android Chrome Custom Tabs
iOS redirect_darwin ASWebAuthenticationSession
macOS redirect_darwin ASWebAuthenticationSession
Linux redirect_desktop Loopback HTTP server + system browser
Windows redirect_desktop Loopback HTTP server + system browser
Web redirect_web Popup / New tab / Same-page / Iframe
CLI (Dart) redirect_io Loopback HTTP server + system browser

Packages

This is a federated plugin. Pick the package that fits your use case:

Package pub.dev Description
redirect pub Flutter plugin — single import for all Flutter targets
redirect_core pub Shared types & RedirectHandler interface (pure Dart)
redirect_platform_interface pub Flutter platform interface
redirect_android pub Android implementation
redirect_darwin pub iOS & macOS implementation
redirect_desktop pub Linux & Windows implementation
redirect_web pub Flutter web implementation
redirect_web_core pub Pure Dart web implementation (no Flutter dependency)
redirect_io pub Pure Dart IO implementation

Quick Start

Flutter

# pubspec.yaml
dependencies:
  redirect: ^0.1.0

Platform packages are endorsed and included automatically — no need to add them individually.

Pure Dart (CLI)

dependencies:
  redirect_io: ^0.1.0

Pure Dart (Web)

dependencies:
  redirect_web_core: ^0.1.0

Web Setup

Web requires a callback page with redirect_callback.js to relay the callback URL via BroadcastChannel. Run dart run redirect_web_core:setup to copy the script to your web/ directory, then include it on your callback page. See CONTRIBUTING.md for details.

Key Concepts

Synchronous Handle

runRedirect() returns a RedirectHandle synchronously. This is critical on web, where the browser window must be opened in the user-gesture call stack to avoid popup blockers. The actual result is awaited separately via handle.result.

Sealed Result Type

RedirectResult is a sealed class with four subtypes:

Type When
RedirectSuccess Callback URI received with query parameters
RedirectCancelled User dismissed the browser or timeout elapsed
RedirectPending Page navigated away (web same-page mode only)
RedirectFailure An error occurred

Options

runRedirect(
  url: redirectUrl,
  callbackUrlScheme: 'myapp',
  options: RedirectOptions(
    timeout: Duration(minutes: 5),
  ),
);

See Use Cases for detailed platform-specific examples including web popup/tab/iframe modes, CLI flows, and more.

Documentation

  • Use Cases — Comprehensive examples for every platform and mode
  • Example App — Runnable Flutter example with full platform configuration
  • API Reference — Generated API docs on pub.dev

Contributing

Contributions are welcome! Please file issues and pull requests on the GitHub repository.

Developer setup and workflows are documented in CONTRIBUTING.md.

License

This project is licensed under the MIT License — see the LICENSE file for details.


Built with 💙 by Bdaya Dev

About

A cross-platform plugin for managing redirect-based flows, like for OAuth Authorization code flow, payment gateways, etc...

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published