-2

I am new to dart and am trying to call a function from my auth.dart file in my sign in page I tried many solutions but it did'nt work out, so any NEW Ideas? This is my auth file:

abstract class BaseAuth{
  Future<FirebaseUser> currentUser();
  Future<String> signIn(String email, String password);
  Future<String> createUser(String email, String password);
  Future<void> signOut();
  Future<String> getEmail();
  Future<bool> isEmailVerified();
  Future<void> resetPassword(String email);
  Future<void> sendEmailVerification();
}
class Auth implements BaseAuth{
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
  Future<String> signIn(String email, String password) async {
    FirebaseUser user = (await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password)) as FirebaseUser;
    return user.uid;
  }
  Future<String> createUser(String email, String password) async {
    FirebaseUser user = (await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password)) as FirebaseUser;
    return user.uid;
  }
  Future<FirebaseUser> currentUser() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    print("uid ${user.uid}");
    return user;
  }
  Future<String> getEmail() async{
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.email;
  }
  Future<void> signOut() async {
    return _firebaseAuth.signOut();
  }
  Future<bool> isEmailVerified() async{
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.isEmailVerified;
  }
  Future<void> resetPassword(String email) async{
    return _firebaseAuth.sendPasswordResetEmail(email: email);
  }
  Future<void> sendEmailVerification() async{
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.sendEmailVerification();
  }
}
Omar Yacop
  • 37
  • 1
  • 9

1 Answers1

1

first you need to import the file. Do this at the very top of your file. You need to provide the path to the file from the current file location. So if current file is in /lib and the new file is in /lib/widgets your path is "widgets/new.dart". You can go up a folder like this "../new.dart"

import 'new.dart';

Then instantiate an object of your class and use that object to call functions.

New x = New();
x.getFromOtherFile();

"New" is my class name in this example.

Benedikt J Schlegel
  • 1,707
  • 1
  • 10
  • 23