如何将设备连接至Moor Inspector?已下载插件但不知如何通过设备IP及端口号完成连接
Hey there! Let's get your device connected to Moor Inspector smoothly—since you already have the plugin installed, we just need to nail down the IP and port setup and walk through the connection steps. Here's a detailed breakdown:
Connecting Your Device to Moor Inspector (IP & Port Guide)
Step 1: Grab Your Device's IP Address
The correct IP depends on what type of device you're using:
- Android Emulator: Use
10.0.2.2—this is a special address that maps your computer's localhost from the emulator's perspective. - Physical Android/iOS Device: Connect it to the same Wi-Fi network as your computer. Then find its IP in settings:
- Android: Go to Settings > About Phone > Status Information > IP Address
- iOS: Go to Settings > Wi-Fi > Tap the info icon next to your network > IP Address
- iOS Simulator: You can use either
localhostor your computer's local IP (the simulator shares your computer's network connection).
Step 2: Confirm the Moor Inspector Port
By default, Moor Inspector uses port 8080 for connections. If you've customized the port in your Flutter project, use that value instead. To set a custom port, update your database initialization code like this:
import 'package:moor/moor.dart'; import 'package:moor_inspector/moor_inspector.dart'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; // Example database setup with custom port LazyDatabase _openConnection() { return LazyDatabase(() async { final dbFolder = await getApplicationDocumentsDirectory(); final file = File(p.join(dbFolder.path, 'your_db_name.sqlite')); // Specify your custom port here return VmDatabase(file, inspector: MoorInspector(port: 9090)); }); }
Step 3: Connect via the Moor Inspector Plugin
Once you have the IP and port, open the plugin in your IDE (Android Studio/VS Code):
- Locate the Moor Inspector panel (usually in the right sidebar, or under View > Tool Windows in Android Studio)
- Enter the full address in the connection field (format:
[IP_ADDRESS]:[PORT]—e.g.,10.0.2.2:8080or192.168.1.105:8080) - Click the "Connect" button to establish the link
Step 4: Troubleshoot if Connection Fails
If the plugin doesn't load your database:
- Double-check that your device and computer are on the same network (critical for physical devices)
- Verify the port matches exactly what's in your project code
- Ensure your Flutter app is running actively on the device/emulator
- Check if your computer's firewall is blocking traffic on the specified port
内容的提问来源于stack exchange,提问作者NM Naufaldo
相关产品推荐
相关产品推荐

