错误:由于返回类型“Never”,因此必须返回非空值。不允许为空

发布于 2025-01-20 05:10:09 字数 2309 浏览 3 评论 0原文

我使用 firebase 在我的 flutter 应用程序中编写了一个通过 google 登录的函数。但是当我尝试运行我的应用程序时,出现以下错误。我当前正在运行 flutter v2.5.3,但我将其升级到 v10...但它仍然不起作用

/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:14:11: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(exception, stackTrace);
      ^^^^^^^^^^^^^^^^^^^
 /C:/src/flutter/flutter/.pub- 
cache/hosted/pub.dartlang.org/firebase_auth_platform_interface- 
6.2.0/lib/src/method_channel/utils/exception.dart:17:9: Error: Method not found: 
'Error.throwWithStackTrace'.
 Error.throwWithStackTrace(
       ^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub- 
cache/hosted/pub.dartlang.org/firebase_auth_platform_interface- 
6.2.0/lib/src/method_channel/utils/exception.dart:12:7: Error: A non-null value must be 
returned since the return type 'Never' doesn't allow null.
Never convertPlatformException(Object exception, StackTrace stackTrace) {
      ^


FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' finished with non-zero exit 
value 1

   * Try:
   Run with --stacktrace option to get the stack trace. Run with --info or --debug 
   option to get more log output. Run with --scan to get full insights.

   * Get more help at https://help.gradle.org

    BUILD FAILED in 10s
    Exception: Gradle task assembleDebug failed with exit code 1

下面是我的函数文件

class GoogleSignInProvider extends ChangeNotifier{
 final googleSignIn=GoogleSignIn();


  GoogleSignInAccount?_user;

  GoogleSignInAccount? get user=>_user!;


  Future googleLogin() async{
    final googleUser=await googleSignIn.signIn();


     if(googleUser != null) return _user=googleUser;

     final googleAuth = await googleUser!.authentication;
     final credential = GoogleAuthProvider.credential(
       accessToken: googleAuth.accessToken,
       idToken: googleAuth.idToken,
      );
      await FirebaseAuth.instance.signInWithCredential(credential);
        notifyListeners();
     }
    }

请帮助!

I wrote a function to login through google in my flutter app using firebase . But when I try to run my app I get the below error.I'm currently running flutter v2.5.3 but I upgraded it to v10... but still it didnt work

/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:14:11: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(exception, stackTrace);
      ^^^^^^^^^^^^^^^^^^^
 /C:/src/flutter/flutter/.pub- 
cache/hosted/pub.dartlang.org/firebase_auth_platform_interface- 
6.2.0/lib/src/method_channel/utils/exception.dart:17:9: Error: Method not found: 
'Error.throwWithStackTrace'.
 Error.throwWithStackTrace(
       ^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub- 
cache/hosted/pub.dartlang.org/firebase_auth_platform_interface- 
6.2.0/lib/src/method_channel/utils/exception.dart:12:7: Error: A non-null value must be 
returned since the return type 'Never' doesn't allow null.
Never convertPlatformException(Object exception, StackTrace stackTrace) {
      ^


FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' finished with non-zero exit 
value 1

   * Try:
   Run with --stacktrace option to get the stack trace. Run with --info or --debug 
   option to get more log output. Run with --scan to get full insights.

   * Get more help at https://help.gradle.org

    BUILD FAILED in 10s
    Exception: Gradle task assembleDebug failed with exit code 1

Below is my function file

class GoogleSignInProvider extends ChangeNotifier{
 final googleSignIn=GoogleSignIn();


  GoogleSignInAccount?_user;

  GoogleSignInAccount? get user=>_user!;


  Future googleLogin() async{
    final googleUser=await googleSignIn.signIn();


     if(googleUser != null) return _user=googleUser;

     final googleAuth = await googleUser!.authentication;
     final credential = GoogleAuthProvider.credential(
       accessToken: googleAuth.accessToken,
       idToken: googleAuth.idToken,
      );
      await FirebaseAuth.instance.signInWithCredential(credential);
        notifyListeners();
     }
    }

Please help!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2025-01-27 05:10:09

尝试将Flutter版本升级到2.10.3。错误将消失。

Try upgrading flutter version to 2.10.3. The Error will be gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文