flutter 에서 https://pub.dev/packages/firebase_dynamic_links 는 android와 ios만 지원하고 web은 지원하지 않는다.
firebase_dynamic_links | Flutter Package
Flutter plugin for Google Dynamic Links for Firebase, an app solution for creating and handling links across multiple platforms.
pub.dev
대신에 rest api를 사용하는 방법도 있었다.
그래서 이번에 firebase function을 이용해서 dynamic link를 받아온 후에 flutter로 보내는 함수를 만들어보도록 하겠다.

유효기간은 따로 설정하지 않으면 계속 유지되는 것으로 보인다.. (아래 참조)
https://stackoverflow.com/questions/48098770/when-will-a-firebase-dynamic-link-expire
When will a firebase dynamic link expire?
I'm trying to figure out how long I can use a Firebase dynamic link (small link). Because currently I am generating a link every time I need one. I want to create one link and send it to hunderds of
stackoverflow.com
https://firebase.google.com/docs/dynamic-links/rest?hl=ko&authuser=0
REST API로 동적 링크 생성 | Firebase 동적 링크
Firebase Summit이 열립니다. 소식 받기 이 페이지는 Cloud Translation API를 통해 번역되었습니다. Switch to English 의견 보내기 REST API로 동적 링크 생성 컬렉션을 사용해 정리하기 내 환경설정을 기준으로
firebase.google.com
여기서 api_key는 gcp에 있는 api_key를 말하는 것 같다.
web apikey는 firebase에서 auto generated 된 것으로 firebase 에서도 가져올 수 있다.
Dio dio = Dio();
Response response = await dio.post(
'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=$apiKey',
data: {
"dynamicLinkInfo": {
"domainUriPrefix": "https://todaymenu.page.link",
"link": url,
"androidInfo": {
"androidPackageName": "com.i305company.todaymenu_flutter1"
},
"iosInfo": {"iosBundleId": "com.i305company.todaymenuFlutter1"}
}
},
options: Options(contentType: Headers.jsonContentType));
logger.d('status code -> ${response.statusCode}');
logger.d('data -> ${response.data}');
return response.data['shortLink'];
성공!

그냥 웹일 때만 이걸로 쓰고 있음!
'개발 > Flutter web' 카테고리의 다른 글
firebase google login (0) | 2022.11.04 |
---|---|
flutter web 에서 webview 사용하기 (0) | 2022.11.01 |
flutter deploy website 지워보기 (0) | 2022.10.30 |
flutter web port 설정하기 (0) | 2022.10.30 |
flutter web deploy 하기 (0) | 2022.10.30 |