vishnuagbly / google_sign_in_all_platforms

2 stars 6 forks source link

Web version not running #8

Open hadi-14 opened 2 months ago

hadi-14 commented 2 months ago

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following UnsupportedError was thrown building AuthHandler(state: _AuthHandlerState#a3b88): Unsupported operation: Platform._operatingSystem

The relevant error-causing widget was: AuthHandler AuthHandler:file:///D:/flutter/franchise_management_app/lib/main.dart:52:33

When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 296:3 throw dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 244:5 _operatingSystem dart-sdk/lib/io/platform_impl.dart 56:40 get operatingSystem dart-sdk/lib/io/platform.dart 83:44 get operatingSystem dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1091:8 get dart-sdk/lib/io/platform.dart 146:48 get isMacOS dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1091:8 get packages/google_sign_in_all_platforms_interface/src/extensions/platform.dart 5:42 get isDesktop packages/google_sign_in_all_platforms/google_sign_in_all_platforms.dart 13:12 new packages/franchise_management_app/auth/firebase_login.dart 46:21 initState packages/flutter/src/widgets/framework.dart 5748:55 [_firstBuild] packages/flutter/src/widgets/framework.dart 5593:5 mount ..

════════════════════════════════════════════════════════════════════════════════════════════════════ Another exception was thrown: Unsupported operation: Platform._operatingSystem

vishnuagbly commented 2 months ago

Will look into it 👀 Remind me on weekend 👀

On Mon, 19 Aug 2024, 1:37 am hadi-14, @.***> wrote:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following UnsupportedError was thrown building AuthHandler(state: _AuthHandlerState#a3b88): Unsupported operation: Platform._operatingSystem

The relevant error-causing widget was: AuthHandler AuthHandler:file:///D:/flutter/franchise_management_app/lib/main.dart:52:33

When the exception was thrown, this was the stack: dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3 throw dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 244:5 _operatingSystem dart-sdk/lib/io/platform_impl.dart 56:40 get operatingSystem dart-sdk/lib/io/platform.dart 83:44 get operatingSystem dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1091:8 get dart-sdk/lib/io/platform.dart 146:48 get isMacOS dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1091:8 get packages/google_sign_in_all_platforms_interface/src/extensions/platform.dart 5:42 get isDesktop packages/google_sign_in_all_platforms/google_sign_in_all_platforms.dart 13:12 new packages/franchise_management_app/auth/firebase_login.dart 46:21 initState packages/flutter/src/widgets/framework.dart 5748:55 [_firstBuild] packages/flutter/src/widgets/framework.dart 5593:5 mount ..

════════════════════════════════════════════════════════════════════════════════════════════════════ Another exception was thrown: Unsupported operation: Platform._operatingSystem

— Reply to this email directly, view it on GitHub https://github.com/vishnuagbly/google_sign_in_all_platforms/issues/8, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMWY3GWQNOAT4XUZGBR3N6TZSD5IZAVCNFSM6AAAAABMWUNBQGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ3TEMJSGQ3TSNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hadi-14 commented 2 months ago

Hey, the Weekend is here. I did resolve this quite a time before and now I don't know how to because I stupidly forgot to have it pushed onto github.

vishnuagbly commented 2 months ago

Got it will look into it 👍🏻

On Sat, 24 Aug 2024, 9:23 pm hadi-14, @.***> wrote:

Hey, the Weekend is here. I did resolve this quite a time before and now I don't know how to because I stupidly forgot to have it pushed onto github.

— Reply to this email directly, view it on GitHub https://github.com/vishnuagbly/google_sign_in_all_platforms/issues/8#issuecomment-2308437566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMWY3GRMRR4PC5HMGWBMKITZTCUADAVCNFSM6AAAAABMWUNBQGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBYGQZTONJWGY . You are receiving this because you commented.Message ID: @.***>

vishnuagbly commented 2 months ago

@hadi-14 how can I reproduce this? I was not able to take a look at the issue completely till now. But you have not provided any steps to reproduce this.

jie-tang commented 2 weeks ago

Hello @vishnuagbly , I got the same issue and here are the steps to reproduce it:

  1. Create an empty flutter project
  2. Run flutter pub add google_sign_in_all_platforms
  3. Edit main.dart file:
    
    import 'package:flutter/material.dart';
    import 'package:google_sign_in_all_platforms/google_sign_in_all_platforms.dart';

class HomeScreen extends StatefulWidget { const HomeScreen({super.key});

@override State createState() => _HomeScreenState(); }

class _HomeScreenState extends State { var _signedIn = false; final GoogleSignIn _googleSignIn = GoogleSignIn( params: const GoogleSignInParams( clientId: '', clientSecret: '', ), );

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Signin Test')), body: Center( child: ElevatedButton( onPressed: () async { GoogleSignInCredentials? creds; if (!_signedIn) { creds = await _googleSignIn.signInOffline(); creds ??= await _googleSignIn.signInOnline(); } else { await _googleSignIn.signOut(); } final signedIn = creds != null; setState(() { _signedIn = signedIn; }); }, child: Text(_signedIn ? 'Sign Out' : 'Sign in'), ), ), ); } }

class MyApp extends StatelessWidget { const MyApp({super.key});

@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData.dark(), home: const HomeScreen(), ); } } void main() => runApp(const MyApp());


4. Run ` flutter run -d web-server --web-hostname localhost --web-port 3000` and opening http://localhost:3000 in the browser will show this error.
jie-tang commented 2 weeks ago

I managed to make the web version work in my project by modifying two files in my local pub-cache to skip the Platform call on web platform.

  1. ~/.pub-cache/hosted/pub.dev/google_sign_in_all_platforms-0.0.4/lib/google_sign_in_all_platforms.dart: two modifications: import kIsWeb and use it to modify the second assert statement.
    
    import 'dart:io';
    import 'package:flutter/foundation.dart' show kIsWeb;

import 'package:google_sign_in_all_platforms_interface/google_sign_in_all_platforms_interface.dart'; import 'package:http/http.dart' as http;

export 'package:google_sign_in_all_platforms_interface/google_sign_in_all_platforms_interface.dart';

///Use this class to perform all types of Google OAuth operations. class GoogleSignIn { ///Use this class to perform all types of Google OAuth operations. GoogleSignIn({GoogleSignInParams params = const GoogleSignInParams()}) : assert( !isDesktop || (params.clientSecret != null && params.clientId != null), 'For Desktop, clientSecret and clientId cannot be null', ), assert( kIsWeb || (!Platform.isAndroid || params.clientId != null), 'For Android, clientId cannot be null', ) { GoogleSignInAllPlatformsInterface.instance.init(params); }

2. Modify ~/.pub-cache/hosted/pub.dev/google_sign_in_all_platforms_interface-0.0.5/lib/src/extensions/platform.dart` to be: 

import 'dart:io'; import 'package:flutter/foundation.dart' show kIsWeb;

///Whether the current [Platform] is a desktop or not. bool get isDesktop => kIsWeb ? false : Platform.isMacOS || Platform.isLinux || Platform.isWindows;

///Whether the current [Platform] is a mobile or not. bool get isMobile => kIsWeb ? true : Platform.isIOS || Platform.isWindows;


In my application I instantiated it with:

final GoogleSignIn _googleSignIn = GoogleSignIn( params: kIsWeb ? const GoogleSignInParams( clientId: 'foo', scopes: ['email', 'profile'], redirectPort: 3000, ) : const GoogleSignInParams( clientId: 'foo', clientSecret: 'bar', ), );


And I had to enable People API in google cloud APIs & Services to make the web version work (my linux version worked without enabling this API).
I am using google_sign_in-6.2.1.