Flutter Tool 在调试运行时,绑定的是本地地址 127.0.0.1 , 所以不能远程访问
在源码中的文件
/flutter/packages/flutter_tools/lib/src/base/dds.dart
Future<void> startDartDevelopmentService(
Uri observatoryUri, {
required Logger logger,
int? hostPort,
bool? ipv6,
bool? disableServiceAuthCodes,
bool cacheStartupProfile = false,
}) async {
final Uri ddsUri = Uri(
scheme: 'http',
host: ((ipv6 ?? false) ? io.InternetAddress.loopbackIPv6 : io.InternetAddress.loopbackIPv4).host,
port: hostPort ?? 0,
);
logger.printTrace(
'Launching a Dart Developer Service (DDS) instance at $ddsUri, '
'connecting to VM service at $observatoryUri.',
);
try {
_ddsInstance = await ddsLauncherCallback(
observatoryUri,
serviceUri: ddsUri,
enableAuthCodes: disableServiceAuthCodes != true,
ipv6: ipv6 ?? false,
// Enables caching of CPU samples collected during application startup.
cachedUserTags: cacheStartupProfile ? const <String>['AppStartUp'] : const <String>[],
uriConverter: context.get<dds.UriConverter>(),
);
unawaited(_ddsInstance?.done.whenComplete(() {
if (!_completer.isCompleted) {
_completer.complete();
}
}));
logger.printTrace('DDS is listening at ${_ddsInstance?.uri}.');
} on dds.DartDevelopmentServiceException catch (e) {
logger.printTrace('Warning: Failed to start DDS: ${e.message}');
if (e.errorCode == dds.DartDevelopmentServiceException.existingDdsInstanceError) {
try {
_existingDdsUri = Uri.parse(
e.message.split(' ').firstWhere((String e) => e.startsWith('http'))
);
} on StateError {
if (e.message.contains('Existing VM service clients prevent DDS from taking control.')) {
throwToolExit('${e.message}. Please rebuild your application with a newer version of Flutter.');
}
logger.printError(
'DDS has failed to start and there is not an existing DDS instance '
'available to connect to. Please file an issue at https://github.com/flutter/flutter/issues '
'with the following error message:\n\n ${e.message}.'
);
// DDS was unable to start for an unknown reason. Raise a StateError
// so it can be reported by the crash reporter.
throw StateError(e.message);
}
}
if (!_completer.isCompleted) {
_completer.complete();
}
rethrow;
}
}
将 host: ((ipv6 ?? false) ? io.InternetAddress.loopbackIPv6 : io.InternetAddress.loopbackIPv4).host,
修改为 host: (ipv6 ?? false) ? io.InternetAddress.loopbackIPv6.host:'0.0.0.0',
使用
git add packages/flutter_tools/lib/src/base/dds.dart
git commit -m "修改调试绑定地址" 提交代码
重新运行 flutter doctor 命令,自动编译 flutter tool 工具