From e387bd783c51f3f15b9833cb396316152601d531 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 22 May 2025 08:53:43 +0000 Subject: [PATCH] apicall --- .../authentication/login/login_widget.dart | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/Screens/authentication/login/login_widget.dart b/lib/Screens/authentication/login/login_widget.dart index 0446170..13cf433 100644 --- a/lib/Screens/authentication/login/login_widget.dart +++ b/lib/Screens/authentication/login/login_widget.dart @@ -1,4 +1,6 @@ import 'dart:convert'; +import 'dart:html' as html; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:frontend/config/apiUrl.dart'; @@ -709,7 +711,9 @@ class _LoginWidgetState extends State { children: [ Expanded( child: ElevatedButton( - onPressed: () => (), + onPressed: () { + handleMS(); + }, style: ElevatedButton.styleFrom( backgroundColor: Colors.white, // Button color foregroundColor: Colors.black, // Text color @@ -815,4 +819,56 @@ class _LoginWidgetState extends State { ), ); } + + + Future handleMS() async { + + final url = '$apiUrl/auth/mslogin'; + print(url); + try { + final response = await http.get( + Uri.parse(url), + headers: { 'Content-Type': 'application/json' } + ); + print("inside try method"); + if (response.statusCode == 200) { + final authUrl = json.decode(response.body)['auth_url']; + print("authurl - $authUrl"); + if(authUrl != ''){ + // final prefs = await SharedPreferences.getInstance(); + // await prefs.setString('auth_token', authUrl); + print('i have auth URL'); + // canLaunchUrl(authUrl); + + if (kIsWeb) { + print("kIsWeb"); + // Use web redirect (e.g., via JS interop or window.location.href) + // redirectTo(url); + + html.window.location.href = authUrl; + } else { + // For mobile/desktop, open in external browser + // launchUrl(Uri.parse(url), + // mode: LaunchMode.externalApplication); + } + // final result = await FlutterWebAuth.authenticate( + // url: authUrl, + // callbackUrlScheme: "myapp", // Use a custom scheme you registered + // ); + }else{ + print('auth URL not Founded'); + throw Exception('auth URL not Founded'); + } + }else{ + final errorMessage = json.decode(response.body)['message']; + print(errorMessage); + throw Exception(errorMessage); + } + } + catch (e) { + print("Error: $e"); + } + + } + }