From e15a24fae26d45aef6f74f2048002fa977b6db06 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:46:14 +0900 Subject: [PATCH 01/25] Refactor: flutter notification version up --- lib/main.dart | 4 ++-- lib/views/taxiView.dart | 3 +++ pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 519a177..7e8042e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,7 +30,7 @@ void main() async { var initializationSettingsAndroid = const AndroidInitializationSettings('@mipmap/ic_launcher'); - var initializationSettingsIOS = const IOSInitializationSettings( + var initializationSettingsIOS = const DarwinInitializationSettings( requestAlertPermission: true, requestBadgePermission: true, requestSoundPermission: true, @@ -93,7 +93,7 @@ class _MyAppState extends State { channel.id, channel.name, channelDescription: channel.description); - var iOSNotiDetails = const IOSNotificationDetails(); + var iOSNotiDetails = const DarwinNotificationDetails(); var details = NotificationDetails(android: androidNotiDetails, iOS: iOSNotiDetails); diff --git a/lib/views/taxiView.dart b/lib/views/taxiView.dart index 76168e3..a89d07f 100644 --- a/lib/views/taxiView.dart +++ b/lib/views/taxiView.dart @@ -11,9 +11,12 @@ import 'package:taxiapp/utils/token.dart'; import 'package:fluttertoast/fluttertoast.dart'; class TaxiView extends HookWidget { + final Uri? init_uri = null; final CookieManager _cookieManager = CookieManager.instance(); late InAppWebViewController _controller; + TaxiView({init_uri}); + @override Widget build(BuildContext context) { final isLoaded = useState(false); diff --git a/pubspec.yaml b/pubspec.yaml index 942979a..757c91b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,7 @@ dependencies: flutter_secure_storage: ^5.0.2 dio: ^4.0.6 firebase_messaging: ^14.2.1 - flutter_local_notifications: ^9.3.2 + flutter_local_notifications: ^13.0.0 firebase_core: ^2.4.0 flutter_web_auth: ^0.5.0 firebase_dynamic_links: ^5.0.0 From a5d270b393a9a816458c08924f085fd10501ec51 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Tue, 21 Mar 2023 21:56:27 +0900 Subject: [PATCH 02/25] Add: FCM message handler --- lib/main.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 7e8042e..e4e6e4f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -84,6 +84,8 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { + String url = ''; + @override void initState() { FirebaseMessaging.onMessage.listen((RemoteMessage message) async { @@ -105,6 +107,16 @@ class _MyAppState extends State { }); super.initState(); + + FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { + print('msg : ${message.data}'); + + if (message.data['url'] != null) { + setState(() { + url = message.data['url']; + }); + } + }); } @override @@ -117,7 +129,11 @@ class _MyAppState extends State { home: Container( color: const Color(0xFF6E3647), child: Container( - child: Container(color: Colors.white, child: TaxiView()), + child: Container( + color: Colors.white, + child: TaxiView( + init_uri: Uri.parse(url), + )), )), ); } From 42d7dbc51969f738c66f88c7abcd1b45addc21ef Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Wed, 22 Mar 2023 01:15:09 +0900 Subject: [PATCH 03/25] Add: Push Navigation --- android/app/src/main/AndroidManifest.xml | 1 + lib/main.dart | 153 +++++++++++++++++------ lib/views/taxiView.dart | 21 +++- 3 files changed, 132 insertions(+), 43 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8faed71..aed0f32 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -42,6 +42,7 @@ + - diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index cb1ef88..e0759f9 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -12,7 +12,7 @@ running. This Theme is only used starting with V2 of Flutter's Android embedding. --> - diff --git a/lib/utils/pushHandler.dart b/lib/utils/pushHandler.dart index 61ef519..1731235 100644 --- a/lib/utils/pushHandler.dart +++ b/lib/utils/pushHandler.dart @@ -23,9 +23,6 @@ Future handleMessage(RemoteMessage message) async { var flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); - print("BACKGROUND SERVICE RUNNED!"); - print(message.toMap()); - ByteArrayAndroidBitmap? largeIcon; if (message.data['icon'] != null) { diff --git a/lib/views/taxiView.dart b/lib/views/taxiView.dart index 661daf6..e3d3046 100644 --- a/lib/views/taxiView.dart +++ b/lib/views/taxiView.dart @@ -54,7 +54,6 @@ class TaxiView extends HookWidget { (await _controller.value!.getUrl()) ?.path .replaceAll("chatting", "myroom")) { - print("SAME URL!"); return; } else { handleMessage(message); @@ -65,11 +64,9 @@ class TaxiView extends HookWidget { flutterLocalNotificationsPlugin.initialize( initializationSettings, onDidReceiveNotificationResponse: (details) { - print("onReceive Payload ${details.payload}"); if (details.payload != null) { String address = dotenv.get("FRONT_ADDRESS"); url.value = address + details.payload!; - print("SET STATE CALLED! ${isFirstLoaded.value}"); isFirstLoaded.value += 1; } }, @@ -93,9 +90,7 @@ class TaxiView extends HookWidget { if (url.value != '') { _controller.value! .loadUrl(urlRequest: URLRequest(url: WebUri(url.value))) - .then((value) { - print("LOAD URL CALLED!"); - }); + .then((value) {}); } }, [isFirstLoaded.value]); @@ -146,83 +141,87 @@ class TaxiView extends HookWidget { WillPopScope( onWillPop: () => _goBack(context, backCount, isAuthLogin, _controller.value), - child: InAppWebView( - initialSettings: InAppWebViewSettings( + child: Scaffold( + body: InAppWebView( + initialSettings: InAppWebViewSettings( useHybridComposition: true, - useShouldOverrideUrlLoading: true), - initialUrlRequest: URLRequest(url: WebUri(address)), - onWebViewCreated: (InAppWebViewController webcontroller) async { - print("웹뷰 로딩중"); - _controller.value = webcontroller; - }, - // React Link는 Page를 로드하는 것이 아니라 history를 바꾸는 것이기 때문에 history 변화로 링크 변화를 감지해야함. - onUpdateVisitedHistory: (controller, url, androidIsReload) async { - // 세션이 만료되어 로그인 페이지로 돌아갈 시 자동으로 세션 갱신 - if (url.toString().contains("login") && - isLogin.value && - isAuthLogin.value) { - try { - String? session = await Token().getSession(); - if (session == null) { - isLogin.value = false; + useShouldOverrideUrlLoading: true, + enableViewportScale: true, + ), + initialUrlRequest: URLRequest(url: WebUri(address)), + onWebViewCreated: (InAppWebViewController webcontroller) async { + _controller.value = webcontroller; + }, + // React Link는 Page를 로드하는 것이 아니라 history를 바꾸는 것이기 때문에 history 변화로 링크 변화를 감지해야함. + onUpdateVisitedHistory: + (controller, url, androidIsReload) async { + // 세션이 만료되어 로그인 페이지로 돌아갈 시 자동으로 세션 갱신 + if (url.toString().contains("login") && + isLogin.value && + isAuthLogin.value) { + try { + String? session = await Token().getSession(); + if (session == null) { + isLogin.value = false; + isAuthLogin.value = false; + } else { + sessionToken.value = session; + await _controller.value!.loadUrl( + urlRequest: URLRequest(url: WebUri(address))); + } + } catch (e) { + // TODO handle error + Fluttertoast.showToast( + msg: "서버와의 연결에 실패했습니다.", + toastLength: Toast.LENGTH_SHORT, + ); isAuthLogin.value = false; - } else { - sessionToken.value = session; - await _controller.value!.loadUrl( - urlRequest: URLRequest(url: WebUri(address))); } - } catch (e) { - // TODO handle error - Fluttertoast.showToast( - msg: "서버와의 연결에 실패했습니다.", - toastLength: Toast.LENGTH_SHORT, - ); - isAuthLogin.value = false; } - } - // 로그아웃 감지 시 토큰 지우고 처음 로그인 페이지로 돌아가기 - if (url.toString().contains("logout") && isLogin.value) { - try { - await FcmToken().removeToken(Token().getAccessToken()); - await Token().deleteAll(); - isLogin.value = false; - isAuthLogin.value = false; - } catch (e) { - // TODO - Fluttertoast.showToast( - msg: "서버와의 연결에 실패했습니다.", - toastLength: Toast.LENGTH_SHORT, - ); - isAuthLogin.value = false; + // 로그아웃 감지 시 토큰 지우고 처음 로그인 페이지로 돌아가기 + if (url.toString().contains("logout") && isLogin.value) { + try { + await FcmToken().removeToken(Token().getAccessToken()); + await Token().deleteAll(); + isLogin.value = false; + isAuthLogin.value = false; + } catch (e) { + // TODO + Fluttertoast.showToast( + msg: "서버와의 연결에 실패했습니다.", + toastLength: Toast.LENGTH_SHORT, + ); + isAuthLogin.value = false; + } } - } - }, - onLoadStart: (controller, uri) async { - _controller.value = controller; - if (sessionToken.value != '') { - try { - await _cookieManager.deleteAllCookies(); - await _cookieManager.setCookie( - url: WebUri(address), - name: "connect.sid", - value: sessionToken.value, - ); - await _cookieManager.setCookie( - url: WebUri(address), - name: "deviceToken", - value: FcmToken().fcmToken, - ); - } catch (e) { - // TODO : handle error - Fluttertoast.showToast( - msg: "서버와의 연결에 실패했습니다.", - toastLength: Toast.LENGTH_SHORT, - ); - isAuthLogin.value = false; + }, + onLoadStart: (controller, uri) async { + _controller.value = controller; + if (sessionToken.value != '') { + try { + await _cookieManager.deleteAllCookies(); + await _cookieManager.setCookie( + url: WebUri(address), + name: "connect.sid", + value: sessionToken.value, + ); + await _cookieManager.setCookie( + url: WebUri(address), + name: "deviceToken", + value: FcmToken().fcmToken, + ); + } catch (e) { + // TODO : handle error + Fluttertoast.showToast( + msg: "서버와의 연결에 실패했습니다.", + toastLength: Toast.LENGTH_SHORT, + ); + isAuthLogin.value = false; + } } - } - }, - onLoadStop: (finish, uri) async {})), + }, + onLoadStop: (finish, uri) async {}), + )), isAuthLogin.value ? Stack() : LoginView(isAuthLogin), isLoaded.value ? Stack() From 8c4d21c8caf9bed8df3ca34e62ad54767c7f3cea Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:29:41 +0900 Subject: [PATCH 17/25] Refactor: remove unused libraries --- pubspec.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5e71d69..437061d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,7 +34,6 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 flutter_hooks: ^0.18.6 - webview_flutter: ^3.0.4 flutter_inappwebview: ^6.0.0-beta.22 flutter_secure_storage: ^8.0.0 dio: ^4.0.6 @@ -42,7 +41,6 @@ dependencies: flutter_local_notifications: ^13.0.0 firebase_core: ^2.8.0 flutter_web_auth: ^0.5.0 - firebase_dynamic_links: ^5.0.0 dio_cookie_manager: ^2.0.0 google_fonts: ^3.0.1 fluttertoast: ^8.1.2 From edb96dd65950c0ca49b59b6bad2b133b7daf3d18 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:35:23 +0900 Subject: [PATCH 18/25] Refactor: Remove and constants --- lib/constants/constants.dart | 2 +- lib/utils/fcmToken.dart | 2 +- lib/utils/token.dart | 4 ++-- lib/views/loginView.dart | 15 ++++++++------- lib/views/taxiView.dart | 3 +-- pubspec.yaml | 1 + 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/constants/constants.dart b/lib/constants/constants.dart index 16846f6..90685fe 100644 --- a/lib/constants/constants.dart +++ b/lib/constants/constants.dart @@ -3,7 +3,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; String address = dotenv.get("BACKEND_ADDRESS"); -final BaseOptions ConnectionOptions = BaseOptions( +final BaseOptions connectionOptions = BaseOptions( baseUrl: address, connectTimeout: 15000, receiveTimeout: 13000, diff --git a/lib/utils/fcmToken.dart b/lib/utils/fcmToken.dart index b7f2e07..7e269da 100644 --- a/lib/utils/fcmToken.dart +++ b/lib/utils/fcmToken.dart @@ -7,7 +7,7 @@ class FcmToken { static FcmToken? _instance; - final Dio _dio = Dio(ConnectionOptions); + final Dio _dio = Dio(connectionOptions); FcmToken._internal({required this.token}); diff --git a/lib/utils/token.dart b/lib/utils/token.dart index 60c308c..459bdac 100644 --- a/lib/utils/token.dart +++ b/lib/utils/token.dart @@ -13,7 +13,7 @@ class Token { static Token? _instance; static final _storage = FlutterSecureStorage(); - final Dio _dio = Dio(ConnectionOptions); + final Dio _dio = Dio(connectionOptions); final CookieJar _cookieJar = CookieJar(); Token._internal({required this.accessToken, required this.refreshToken}); @@ -76,7 +76,7 @@ class Token { } if (response.statusCode == 200) { List cookies = await _cookieJar.loadForRequest( - Uri.parse(ConnectionOptions.baseUrl + "auth/app/token/login")); + Uri.parse(connectionOptions.baseUrl + "auth/app/token/login")); for (Cookie cookie in cookies) { if (cookie.name == "connect.sid") { return cookie.value; diff --git a/lib/views/loginView.dart b/lib/views/loginView.dart index 52a88a4..e06188d 100644 --- a/lib/views/loginView.dart +++ b/lib/views/loginView.dart @@ -23,7 +23,7 @@ class LoginView extends HookWidget { final _url = Uri.parse(_backUrl).replace(path: "api/auth/app/token/generate"); - final callbackUrlScheme = "org.sparcs.taxiapp"; + const callbackUrlScheme = "org.sparcs.taxiapp"; final result = await FlutterWebAuth.authenticate( url: _url.toString(), @@ -45,23 +45,24 @@ class LoginView extends HookWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image(image: AssetImage('assets/img/taxiLogoText.png'), height: 60), - Padding(padding: EdgeInsets.only(top: 15)), + const Image( + image: AssetImage('assets/img/taxiLogoText.png'), height: 60), + const Padding(padding: EdgeInsets.only(top: 15)), OutlinedButton( style: ButtonStyle( - fixedSize: MaterialStateProperty.all(Size(250, 45)), + fixedSize: MaterialStateProperty.all(const Size(250, 45)), backgroundColor: - MaterialStateProperty.all(Color(0xFF6E3678)), + MaterialStateProperty.all(const Color(0xFF6E3678)), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(12.0), - side: BorderSide(color: Colors.black), + side: const BorderSide(color: Colors.black), ), ), ), child: Text("로그인", style: GoogleFonts.roboto( - textStyle: TextStyle( + textStyle: const TextStyle( color: Colors.white, fontSize: 15, fontWeight: FontWeight.bold))), diff --git a/lib/views/taxiView.dart b/lib/views/taxiView.dart index e3d3046..e2d69e7 100644 --- a/lib/views/taxiView.dart +++ b/lib/views/taxiView.dart @@ -14,13 +14,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; class TaxiView extends HookWidget { - Uri? init_uri; final CookieManager _cookieManager = CookieManager.instance(); // late InAppWebViewController _controller; FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); - TaxiView({this.init_uri}); + TaxiView(); @override Widget build(BuildContext context) { diff --git a/pubspec.yaml b/pubspec.yaml index 437061d..e3667aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,7 @@ dependencies: dio_cookie_manager: ^2.0.0 google_fonts: ^3.0.1 fluttertoast: ^8.1.2 + cookie_jar: ^3.0.1 dev_dependencies: flutter_test: From ec93cae5fa285020aa6f94ed345b9446f50a8945 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:44:44 +0900 Subject: [PATCH 19/25] Refactor: remove Unused imports and add pubspec.yaml --- android/app/build.gradle | 2 +- android/app/src/debug/AndroidManifest.xml | 2 +- android/app/src/main/AndroidManifest.xml | 2 +- android/app/src/profile/AndroidManifest.xml | 2 +- lib/main.dart | 2 -- pubspec.yaml | 4 ++-- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 935e51b..4bad09c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -68,7 +68,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "org.sparcs.taxiapp" + applicationId "org.sparcs.taxi_app" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion 21 // flutter.minSdkVersion diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index d668a4d..9338b2b 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="org.sparcs.taxi_app">