Flutter

[Flutter]WebView localhost 연결 시 에러

코린이탈출기 2024. 11. 19. 11:09
728x90

 

 

1. net::ERR_CLEARTEXT_NOT_PERMITTED

http 주소를 사용할 경우

AndroidManifest.xml에 아래 코드 추가

 

android:usesCleartextTraffic="true"

 

 

 

2. net::ERR_CONNECTION REFUSED

 

로컬 테스트로 인해 WebView Uri을 http://localhost:8080/ 으로 주었더니 연결할 수 있는 곳이 없어 나는 오류였다.

 

안드로이드와 프로젝트를 띄운 컴퓨터의 와이파이를 동일하게 맞춰서 해결할 수 있다.

 

(Mac에서 ip 주소 확인하기)

터미널에 ifconfig를 입력하여 와이파이의 ip 주소를 확인할 수 있다.

출력된 결과 중 "en0" 섹션을 찾는다.

 

예:

inet 192.168.1.101

 

코드에 반영

// 변경 전 localhost로 호출
..loadRequest(Uri.parse('http://localhost:8080'));

// 변경 후 web ip로 호출
..loadRequest(Uri.parse('http://192.168.20.138:8080'));


 

 

 

 

[참고]

https://ddol.tistory.com/38

 

 

 

728x90