Flutter 未处理的异常:PlatformException(执行get时出错,由于客户端脱机而无法获取文档,null)

Flutter 未处理的异常:PlatformException(执行get时出错,由于客户端脱机而无法获取文档,null),flutter,Flutter,我正在尝试使用谷歌登录。但这是一个错误。我已经尝试了很多解决方案,这是对stackoverflow提供的。但仍然显示出同样的错误。firebase A计数也已连接。我尝试了另一个很好的例子。但在这方面,我也使用了firebase通知 这是主飞镖 void main() async { WidgetsFlutterBinding.ensureInitialized(); //Firestore.instance.settings(timestampsInSnapshotsEnabled:

我正在尝试使用谷歌登录。但这是一个错误。我已经尝试了很多解决方案,这是对stackoverflow提供的。但仍然显示出同样的错误。firebase A计数也已连接。我尝试了另一个很好的例子。但在这方面,我也使用了firebase通知

这是主飞镖

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  //Firestore.instance.settings(timestampsInSnapshotsEnabled: true);
  //await Firestore.instance.settings(host: "localhost:8080", sslEnabled: false);

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fanz',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        scaffoldBackgroundColor: Colors.black,
        dialogBackgroundColor: Colors.black,
        primarySwatch: Colors.grey,
        accentColor: Colors.black,
        cardColor: Colors.white70,
      ),
      home: HomePage(),
    );
  }
}
首页.dart

    final GoogleSignIn gSignIn = GoogleSignIn();
final usersReference = Firestore.instance.collection("users");
final StorageReference storageReference =
    FirebaseStorage.instance.ref().child("Posts Pictures");
final postsReference = Firestore.instance.collection("posts");
final activityFeedReference = Firestore.instance.collection("feed");
final commentsRefrence = Firestore.instance.collection("comments");
final followersRefrence = Firestore.instance.collection("followers");
final followingRefrence = Firestore.instance.collection("following");
final timelineRefrence = Firestore.instance.collection("timeline");

final DateTime timestamp = DateTime.now();
User currentUser;

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool isSignedIn = false;
  PageController pageController;
  int getPageIndex = 0;
  FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  void initState() {
    secureScreen();
    super.initState();

    pageController = PageController();

    gSignIn.onCurrentUserChanged.listen((gSigninAccount) {
      controlSignIn(gSigninAccount);
    }, onError: (gError) {
      print("Error Message: " + gError);
    });

    gSignIn.signInSilently(suppressErrors: false).then((gSignInAccount) {
      print("Arpit Singh1");
      controlSignIn(gSignInAccount);
    }).catchError((gError) {
      print("Error Message: " + gError);
    });
  }

  Future<void> secureScreen() async {
    await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
  }

  controlSignIn(GoogleSignInAccount signInAccount) async {
    if (signInAccount != null) {
      print("Arpit Singh2");
      await saveUserInfoToFireStore();

      setState(() {
        isSignedIn = true;
      });

      configureRealTimePushNotifications();
    } else {
      setState(() {
        isSignedIn = false;
      });
    }
  }

  configureRealTimePushNotifications() {
    final GoogleSignInAccount gUser = gSignIn.currentUser;

    if (Platform.isIOS) {
      getIOSPermissions();
    }

    _firebaseMessaging.getToken().then((token) {
      usersReference
          .document(gUser.id)
          .updateData({"androidNotificationToken": token});
    });

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> msg) async {
        final String recipientId = msg["data"]["recipient"];
        final String body = msg["notification"]["body"];

        if (recipientId == gUser.id) {
          SnackBar snackBar = SnackBar(
            backgroundColor: Colors.grey,
            content: Text(
              body,
              style: TextStyle(color: Colors.black),
              overflow: TextOverflow.ellipsis,
            ),
          );
          _scaffoldKey.currentState.showSnackBar(snackBar);
        }
      },
    );
  }

  getIOSPermissions() {
    _firebaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(alert: true, badge: true, sound: true));

    _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
      print("Settings Registered :  $settings");
    });
  }

  saveUserInfoToFireStore() async {
    print("Arpit Singh3");
    final GoogleSignInAccount gCurrentUser = gSignIn.currentUser;
    DocumentSnapshot documentSnapshot =
        await usersReference.document(gCurrentUser.id).get();

    if (!documentSnapshot.exists) {
      final username = await Navigator.push(context,
          MaterialPageRoute(builder: (context) => CreateAccountPage()));

      usersReference.document(gCurrentUser.id).setData({
        "id": gCurrentUser.id,
        "profileName": gCurrentUser.displayName,
        "username": username,
        "url": gCurrentUser.photoUrl,
        "email": gCurrentUser.email,
        "bio": "",
        "timestamp": timestamp,
      });

      await followersRefrence
          .document(gCurrentUser.id)
          .collection("userFollowers")
          .document(gCurrentUser.id)
          .setData({});

      documentSnapshot = await usersReference.document(gCurrentUser.id).get();
    }

    currentUser = User.fromDocument(documentSnapshot);
  }

  void dispose() {
    pageController.dispose();
    super.dispose();
  }

  loginUser() {
    gSignIn.signIn();
  }

  logoutUser() {
    gSignIn.signOut();
  }

  whenPageChanges(int pageIndex) {
    setState(() {
      this.getPageIndex = pageIndex;
    });
  }

  onTapChangePage(int pageIndex) {
    pageController.animateToPage(
      pageIndex,
      duration: Duration(milliseconds: 400),
      curve: Curves.bounceInOut,
    );
  }

  Scaffold buildHomeScreen() {
    return Scaffold(
      key: _scaffoldKey,
      body: PageView(
        children: <Widget>[
          TimeLinePage(
            gCurrentUser: currentUser,
          ),
          SearchPage(),
          UploadPage(
            gCurrentUser: currentUser,
          ),
          NotificationsPage(),
          ProfilePage(userProfileId: currentUser?.id),
        ],
        controller: pageController,
        onPageChanged: whenPageChanges,
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: CupertinoTabBar(
        currentIndex: getPageIndex,
        onTap: onTapChangePage,
        backgroundColor: Theme.of(context).accentColor,
        activeColor: Colors.white,
        inactiveColor: Colors.blueGrey,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home)),
          BottomNavigationBarItem(icon: Icon(Icons.search)),
          BottomNavigationBarItem(
              icon: Icon(
            Icons.photo_camera,
            size: 37.0,
          )),
          BottomNavigationBarItem(icon: Icon(Icons.favorite)),
          BottomNavigationBarItem(icon: Icon(Icons.person)),
        ],
      ),
    );
  }

  Scaffold buildSignInScreen() {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topRight,
            end: Alignment.bottomLeft,
            colors: [
              Theme.of(context).accentColor,
              Theme.of(context).primaryColor
            ],
          ),
        ),
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(
              "Fanz",
              style: TextStyle(
                  fontSize: 92.0, color: Colors.white, fontFamily: "Signatra"),
            ),
            /* Padding(
                padding: EdgeInsets.all(10.0),
                child: SignInButton(
                  Buttons.Email,
                  text: "Sign up with Email",
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => EmailSignUp()),
                    );
                  },
                )),*/
            GestureDetector(
              onTap: loginUser,
              child: Container(
                width: 270.0,
                height: 65.0,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage("assets/images/google_signin_button.png"),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    if (isSignedIn) {
      return buildHomeScreen();
    } else {
      return buildSignInScreen();
    }
  }
}
final GoogleSignIn gSignIn=GoogleSignIn();
最终用户引用=Firestore.instance.collection(“用户”);
最终存储参考存储参考=
FirebaseStorage.instance.ref().child(“发布图片”);
final postsReference=Firestore.instance.collection(“posts”);
最终activityFeedReference=Firestore.instance.collection(“提要”);
最终评论frence=Firestore.instance.collection(“评论”);
final followerreference=Firestore.instance.collection(“followers”);
final followerreference=Firestore.instance.collection(“following”);
最终TimeLineReference=Firestore.instance.collection(“时间线”);
final DateTime timestamp=DateTime.now();
用户当前用户;
类主页扩展了StatefulWidget{
@凌驾
_HomePageState createState()=>\u HomePageState();
}
类_HomePageState扩展状态{
bool-isSignedIn=false;
页面控制器;
int getPageIndex=0;
FirebaseMessaging_FirebaseMessaging=FirebaseMessaging();
最终_scaffoldKey=GlobalKey();
void initState(){
secureScreen();
super.initState();
pageController=pageController();
gSignIn.onCurrentUserChanged.listen((gSigninAccount){
控制信号(gSigninAccount);
},onError:(gError){
打印(“错误消息:+gError”);
});
gSignIn.signalily(suppressErrors:false)。然后((gSignInAccount){
打印(“Arpit Singh1”);
控制信号(gSignInAccount);
}).catchError((gError){
打印(“错误消息:+gError”);
});
}
Future secureScreen()异步{
等待FlatterWindowManager.addFlags(FlatterWindowManager.FLAG\u安全);
}
controlSignIn(谷歌签名计数签名计数)异步{
if(signInAccount!=null){
打印(“Arpit Singh2”);
等待saveUserInfoToFireStore();
设置状态(){
isSignedIn=true;
});
配置RealtimePushNotifications();
}否则{
设置状态(){
isSignedIn=假;
});
}
}
configureRealTimePushNotifications(){
最终GoogleSignInAccount gUser=gSignIn.currentUser;
if(Platform.isIOS){
getIOS权限();
}
_firebaseMessaging.getToken().then((令牌){
用户引用
.文件(gUser.id)
.updateData({“androidNotificationToken”:token});
});
_firebaseMessaging.configure(
onMessage:(映射消息)异步{
最终字符串recipientId=msg[“数据”][“收件人”];
最后一个字符串body=msg[“notification”][“body”];
if(recipientId==gUser.id){
SnackBar SnackBar=SnackBar(
背景颜色:颜色。灰色,
内容:文本(
身体,
样式:TextStyle(颜色:Colors.black),
溢出:TextOverflow.省略号,
),
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
},
);
}
getIOS权限(){
_firebaseMessaging.requestNotificationPermissions(
IONotificationSettings(警报:true、徽章:true、声音:true));
_firebaseMessaging.OnAssettingsRegistered.listen((设置){
打印(“已注册设置:$Settings”);
});
}
saveUserInfoToFireStore()异步{
打印(“Arpit Singh3”);
最终GoogleSignInAccount gCurrentUser=gSignIn.currentUser;
文档快照文档快照=
wait usersReference.document(gCurrentUser.id).get();
如果(!documentSnapshot.exists){
最终用户名=wait Navigator.push(上下文,
MaterialPageRoute(生成器:(上下文)=>CreateAccountPage());
usersReference.document(gCurrentUser.id).setData({
“id”:gCurrentUser.id,
“profileName”:gCurrentUser.displayName,
“用户名”:用户名,
“url”:gCurrentUser.photoUrl,
“电子邮件”:gCurrentUser.email,
“生物”:“生物”,
“时间戳”:时间戳,
});
等待后续参考
.document(gCurrentUser.id)
.collection(“用户关注者”)
.document(gCurrentUser.id)
.setData({});
documentSnapshot=await usersReference.document(gCurrentUser.id).get();
}
currentUser=User.fromDocument(documentSnapshot);
}
无效处置(){
pageController.dispose();
super.dispose();
}
登录用户(){
gSignIn.signIn();
}
logoutUser(){
gSignIn.signOut();
}
whenPageChanges(整版索引){
设置状态(){
this.getPageIndex=pageIndex;
});
}
onTapChangePage(intpageindex){
pageController.animateToPage(
页面索引,
持续时间:持续时间(毫秒:400),
曲线:Curves.bounceInOut,
);
}
脚手架建筑主屏幕(){
返回脚手架(
钥匙:_scaffoldKey,
正文:页面视图(
儿童:[
时间线页面(
gCurrentUser:currentUser,
),
SearchPage(),
上传页面(
gCurrentUser:currentUser,
),
NotificationsPage(),
ProfilePage(userProfileId:currentUser?.id),
],
控制器:页面控制器,
onPageChanged:当页面更改时,
物理学:NeverscrollableScroll物理学(),
),
底部导航栏:CupertinoTabBar(
currentIndex:getPageIndex,
onTap:onTapChangePage,
背景色:主题。背景色,
activeColor:Colors.white,
不活动颜色:颜色。蓝灰色,
项目:[
BottomNavigationBarItem(图标:图标(Icons.home)),
BottomNavigationBarItem(图标:图标(Icons.search)),
底部导航气压计(