Reputation: 231
I have implemented a class in a file user_service.dart:
class UserService {
Future<User> createUser(...)
....
}
I have tried referencing the createUser method in another class
I import the User Service class
import 'user_service.dart';
and try
UserService userService;
print(userService.toString());
UserService.createUser(....);
It compiles fine.
A am getting an error: NoSuchMethodError: The method 'createUser' was called on null.
Any ideas?
Help appreciated.
Upvotes: 0
Views: 320
Reputation: 4741
In your case you need firstly create a new instance of you UserService class.
UserService _instance = UserService(); // here you are creating a new instance with a default constructor
//now you can call your UserService methods
_instance.createUser();
Upvotes: 2