Flutter plugin for Cloudflare Tunnel (cloudflared) with optional local HTTP server.
This project uses the official cloudflared source code as a git submodule, allowing easy updates to the latest version.
- Cloudflared tunnel connection to Cloudflare's global network
- Optional: Built-in Go HTTP file server with request logging
- Tunnel can be used standalone with any Dart HTTP server (shelf, etc.)
- Real-time connection status and logging
cloudflared_flutter/
├── cloudflared/ # Git submodule from cloudflare/cloudflared
├── mobile/ # Go wrapper for mobile (gomobile bindings)
│ ├── cloudflared.go # Tunnel wrapper
│ ├── server.go # Optional HTTP server
│ ├── build.sh # Build script
│ └── go.mod # Go module (uses cloudflared submodule)
└── flutter_plugin/ # Flutter plugin
└── cloudflared_tunnel/
├── lib/ # Dart API
├── android/ # Android platform code
├── ios/ # iOS platform code (planned)
└── example/ # Example app
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile initgit clone --recursive https://github.com/agusibrahim/cloudflared_flutter.git
cd cloudflared_flutter
# Or if already cloned without --recursive:
git submodule update --init --recursivecd cloudflared
git fetch origin
git checkout origin/master # or specific tag
cd ..
git add cloudflared
git commit -m "Update cloudflared submodule"# Build Android AAR
cd mobile
./build.sh android
# Build iOS Framework
./build.sh ios
# Build both
./build.sh allcd flutter_plugin/cloudflared_tunnel/example
flutter pub get
flutter runimport 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:cloudflared_tunnel/cloudflared_tunnel.dart';
// Start your Dart HTTP server first
final handler = shelf.Pipeline()
.addMiddleware(shelf.logRequests())
.addHandler((request) => shelf.Response.ok('Hello from Dart!'));
final server = await shelf_io.serve(handler, '127.0.0.1', 3000);
// Then start tunnel pointing to your Dart server
final plugin = CloudflaredTunnel();
await plugin.startTunnel(
token: 'your-tunnel-token',
originUrl: 'http://127.0.0.1:3000',
);
// Your Dart server is now publicly accessible via Cloudflare!final plugin = CloudflaredTunnel();
// Start the built-in Go file server
await plugin.startServer(
rootDir: '/path/to/serve',
port: 8080,
);
// Start tunnel with the Go server as origin
await plugin.startTunnel(
token: 'your-tunnel-token',
originUrl: 'http://127.0.0.1:8080',
);
// Listen to request logs from Go server
plugin.requestLogStream.listen((log) {
print('${log.method} ${log.path} - ${log.statusCode}');
});final plugin = CloudflaredTunnel();
await plugin.startAll(
token: 'your-tunnel-token',
rootDir: '/path/to/serve',
port: 8080,
);- Go to Cloudflare Zero Trust Dashboard
- Navigate to Networks > Tunnels
- Create a new tunnel
- Copy the tunnel token
This project is licensed under the Apache 2.0 License - same as cloudflared.
- Cloudflare for cloudflared
- gomobile for Go to mobile bindings