netlink
A drop-in Flutter widget that discovers servers on the local network over
Bonjour/mDNS and saves the selected one locally. Add the dependency, use
NetworkConfigScreen — the code stays in the package; nothing is copied into
your app.
Install
flutter pub add netlink
Use
import 'package:flutter/material.dart';
import 'package:netlink/netlink.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: NetworkConfigScreen());
}
}
Tap Scan network → discovered servers appear → tap one to save it locally.
Configure
NetworkConfigScreen is a normal widget — configure it via constructor args, no
forking required:
NetworkConfigScreen(
storageKey: 'my_app_server', // shared_preferences key
targetName: 'Server', // highlight/sort matching names first
scanTimeout: const Duration(seconds: 6),
title: 'Pick a server',
onSaved: (server) {
// navigate into your app once a server is chosen
Navigator.of(context).pushReplacementNamed('/home');
},
)
Read the saved server anywhere:
final saved = await const ServerStore(storageKey: 'my_app_server').load();
if (saved != null) print(saved.url); // e.g. ws://192.168.1.42:8080
Or run discovery yourself:
final devices = await MdnsDiscovery.scan(targetName: 'Server');
Platform setup (required for mDNS)
Android — automatic
The permissions needed for discovery are provided transitively by bonsoir and
merged into your app. Nothing to do.
iOS — one manual step
Apple requires the app itself to declare Local Network + Bonjour usage; a
package cannot inject this. Add to ios/Runner/Info.plist:
<key>NSLocalNetworkUsageDescription</key>
<string>This app discovers servers on your local network.</string>
<key>NSBonjourServices</key>
<array>
<string>_ws._tcp</string>
<string>_http._tcp</string>
</array>
Prefer it automated? The companion
netlink_clipackage patchesInfo.plist(and the Android manifest), and wiresNetworkConfigScreenas your default route:dart pub global activate netlink_cli netlink setup # or: 4bnetlink setup
Discovered service types
| Protocol | mDNS service type | URL scheme |
|---|---|---|
| WebSocket | _ws._tcp |
ws:// |
| Socket.IO | _http._tcp |
http:// |
Notes
- Discovery uses
bonsoir(native NSD / NSNetServiceBrowser), so it works on real iOS devices under Local Network Privacy — the first scan triggers the system permission prompt. - Run on a real device or two machines on the same Wi-Fi; a server must be
advertising
_ws._tcpor_http._tcpfor anything to appear.
Libraries
- netlink
- A drop-in Flutter widget that discovers servers on the local network over Bonjour/mDNS and saves the selected one locally.