selfteaching/How-To-Ask-Questions-The-Smart-Way

error: The class 'User' doesn't have a default constructor. (new_with_undefined_constructor_default at [tunedin] lib/resources/firebase_methods.dart:12)

goc20 opened this issue · 0 comments

goc20 commented

//This is my firebase_methods.dart file
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:tunedin/utils/utilities.dart';

class FirebaseMethods {
final FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn _googleSignIn = GoogleSignIn();
static final Firestore firestore = Firestore.instance;

//user class
User user = User();

Future getCurrentUser() async {
FirebaseUser currentUser;
currentUser = await _auth.currentUser;
return currentUser;
}

Future signIn() async {
GoogleSignInAccount _signInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication _signInAuthentication =
await _signInAccount.authentication;

final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: _signInAuthentication.accessToken,
    idToken: _signInAuthentication.idToken);

FirebaseUser user = await _auth.signInWithCredential(credential);
return user;

}

Future authenticateUser(FirebaseUser user) async {
QuerySnapshot result = await firestore
.collection("users")
.where("email", isEqualTo: user.email)
.getDocuments();

final List<DocumentSnapshot> docs = result.documents;

//if user is registered then length of list > 0 or else less than 0
return docs.length == 0 ? true : false;

}

Future addDataToDb(FirebaseUser currentUser) async {
String username = Utils.getUsername(currentUser.email);

user = User(
    uid: currentUser.uid,
    email: currentUser.email,
    name: currentUser.displayName,
    profilePhoto: currentUser.photoUrl,
    username: username);

firestore
    .collection("users")
    .document(currentUser.uid)
    .setData(user.toMap(user));

}

Future signOut() async {
await _googleSignIn.disconnect();
await _googleSignIn.signOut();
return await _auth.signOut();
}

}


//This is my firebase_auth.dart file
Screenshot 2020-11-25 at 7 25 46 PM
Screenshot 2020-11-25 at 7 25 58 PM

// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

library firebase_auth;

import 'dart:async';

import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart';
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

export 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart'
show
FirebaseAuthException,
IdTokenResult,
UserMetadata,
UserInfo,
ActionCodeInfo,
ActionCodeSettings,
AdditionalUserInfo,
ActionCodeInfoOperation,
Persistence,
PhoneVerificationCompleted,
PhoneVerificationFailed,
PhoneCodeSent,
PhoneCodeAutoRetrievalTimeout,
AuthCredential,
EmailAuthProvider,
EmailAuthCredential,
FacebookAuthProvider,
FacebookAuthCredential,
GithubAuthProvider,
GithubAuthCredential,
GoogleAuthProvider,
GoogleAuthCredential,
OAuthProvider,
OAuthCredential,
PhoneAuthProvider,
PhoneAuthCredential,
SAMLAuthProvider,
TwitterAuthProvider,
TwitterAuthCredential,
RecaptchaVerifierOnSuccess,
RecaptchaVerifierOnExpired,
RecaptchaVerifierOnError,
RecaptchaVerifierSize,
RecaptchaVerifierTheme;

export 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
show FirebaseException;

part 'src/firebase_auth.dart';
part 'src/user_credential.dart';
part 'src/user.dart';
part 'src/confirmation_result.dart';
part 'src/recaptcha_verifier.dart';