A cross-platform Dart & Flutter plugin for redirect-based flows.
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 | 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 |
This is a federated plugin. Pick the package that fits your use case:
| Package | pub.dev | Description |
|---|---|---|
redirect |
Flutter plugin — single import for all Flutter targets | |
redirect_core |
Shared types & RedirectHandler interface (pure Dart) |
|
redirect_platform_interface |
Flutter platform interface | |
redirect_android |
Android implementation | |
redirect_darwin |
iOS & macOS implementation | |
redirect_desktop |
Linux & Windows implementation | |
redirect_web |
Flutter web implementation | |
redirect_web_core |
Pure Dart web implementation (no Flutter dependency) | |
redirect_io |
Pure Dart IO implementation |
# pubspec.yaml
dependencies:
redirect: ^0.1.0Platform packages are endorsed and included automatically — no need to add them individually.
dependencies:
redirect_io: ^0.1.0dependencies:
redirect_web_core: ^0.1.0Web 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.
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.
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 |
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.
- 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
Contributions are welcome! Please file issues and pull requests on the GitHub repository.
Developer setup and workflows are documented in CONTRIBUTING.md.
This project is licensed under the MIT License — see the LICENSE file for details.
Built with 💙 by Bdaya Dev