代码之家  ›  专栏  ›  技术社区  ›  Lukas Luke Stateczny

未定义FacebookLogin的方法

  •  1
  • Lukas Luke Stateczny  · 技术社区  · 7 年前

    我的Fatter_facebook_软件包已成功连接到该应用程序,但出于某些原因 fbLogin.logInWithReadPermissions 显示:

    [dart] The method 'logInWithReadPermissions' isn't defined for the class 'FacebookLogin'
    

    import 'package:flutter/material.dart';
    
    //facebook signUp
    import 'package:flutter_facebook_login/flutter_facebook_login.dart';
    import 'package:firebase_auth/firebase_auth.dart';
    
    class FacebookLogin extends StatefulWidget {
      @override
      _FacebookLoginState createState() => _FacebookLoginState();
    }
    
    class _FacebookLoginState extends State<FacebookLogin> {
    
      FacebookLogin fbLogin = new FacebookLogin();
    
      @override
      Widget build(BuildContext context) {
        return 
          Container(
            height: 40.0,
            child: Material(
              borderRadius: BorderRadius.circular(20.0),
              shadowColor: Colors.blueAccent,
              color: Color.fromARGB(255, 76, 112, 166),
              elevation: 7.0,
              child: GestureDetector(
                onTap: () {
                  fbLogin.logInWithReadPermissions(['email', 'public_profile']).then((result) {
                    switch(result.status) {
                      case FacebookLoginStatus.loggedIn:
                      FirebaseAuth.instance.signInWithFacebook(
                        accessToken: result.accessToken.token
                      ).then((signedInUser) {
                        print('Sighned in as ${signedInUser.displayName}');
                        Navigator.of(context).pushReplacementNamed('/homepage');
                      }).catchError((e) {
                        print(e);
                      });
                    }
                  })
                  .catchError((e) {
                    print(e);
                  });
                },
                child: Center(
                  child: Text('Log in with facebook',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'Monserrat'
                    )),
                ),
              ),
            ),
          );
      }
    }
    
    1 回复  |  直到 7 年前
        1
  •  18
  •   David García Bodego    6 年前

    替换 fbLogin.logInWithReadPermissions(['email']); fbLogin.logIn(['email']);

        2
  •  7
  •   thusith.92    6 年前

    flutter_facebook_login 3.0.0 ,他们已删除不推荐的方法 loginWithPublishPermissions loginWithReadPermission 到 login .

        3
  •  3
  •   Günter Zöchbauer    7 年前

    class FacebookLogin

    import 'package:flutter_facebook_login/flutter_facebook_login.dart';
    

    重命名你的小部件类,它就会工作。

    或者,您可以使用

    import 'package:flutter_facebook_login/flutter_facebook_login.dart' as fl;
    ...
    fl.FacebookLogin fbLogin = new fl.FacebookLogin();
    
        4
  •  2
  •   M--    6 年前

    flutter_facebook_login 版本3.0.0,因为它们已被替换 logInwithReadPermissions() logIn() . 只用 登录() 相反我的问题就这样解决了。

        5
  •  0
  •   csabinho    6 年前

    如下

    import 'package:flutter_facebook_login/flutter_facebook_login.dart' as fl;
    class _FacebookLoginState extends State {
    
    FacebookLogin fbLogin = new FacebookLogin();
    
    ...
    
    
    ...
    
    ...
    
    fl.logInwithReadPermissions(['email', 'public_profile']).then(result) // this is where you have to modify and everything remains same
    
    if then also problem persists then instead of fl.logInWithReadPermissions(['email', 'public_profile']).then(result) follow as below
    
    fl.logIn(['email', 'public_profile']).then(result)