Registering new user

I’m struggling to register a new user on my backendless need assistance

My whatsapp number is +27711748599

Hello @Enos_Baloyi . Welcome to Backendless Community!

Please describe in detail the steps you take when registering a user.

Regards,
Inna

Future createUser(BackendlessUser user) async {
String result = ‘OK’;
try {
await Backendless.userService.register(user);
NoteEntry emptyEntry = NoteEntry(notes: {}, username: user.email);
await Backendless.data
.of(‘NoteEntry’)
.save(emptyEntry.toJson())
.onError((error, stackTrace) {
result = error.toString();
});
} catch (e) {
result = getHumanReadableError(e.toString());
}
notifyListeners();
return result;
}

Is there an error when you run the code?

I get no errors I can share my code via whatsapp my number is +27711748599

This forum is the only mechanism to get technical support, we do not offer support via whatsapp or other messengers.

Have you debugged the code to see if you get to the point when the registration call occurs? Does the code get the return value?

It does not get a return value let me try sharing my whole code with you here

class InitApp {
static const String apiKeyAndroid =
‘E73146BD-1103-4DDE-B658-265C6EC37A2B’; //add your own key
static const String apiKeyIOS =
‘47BEC51A-807B-47A1-908D-E3E3A098D62F’; //add your own key
static const String appID =
‘79B750D9-B0FA-F382-FFF2-F74E2A419100’; // add your own key

static void initializeApp() async {
await Backendless.initApp(
androidApiKey: apiKeyAndroid,
iosApiKey: apiKeyIOS,
applicationId: appID);

}
}

///////////////////////////////////////////////////////////////////////////////////
//main page

void main() {
WidgetsFlutterBinding.ensureInitialized();
InitApp.initializeApp();
setupLocator();
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => UserManagementViewModel(),
),
ChangeNotifierProvider(
create: (context) => NoteViewModel(),
),
],
child: MaterialApp(
navigatorKey: navigatorKey,
onGenerateRoute: RouteManager.onGenerateRoute,
initialRoute: RouteManager.registerPage,
),
);
}
}

///////////////////////////////////////////////////////////////////////////////

class RegisterForm extends StatefulWidget {
const RegisterForm({
Key? key,
}) : super(key: key);

@override
State createState() => _RegisterFormState();
}

class _RegisterFormState extends State {
late TextEditingController emailController;
late TextEditingController passwordController;
late TextEditingController retypePasswordController;

@override
void initState() {
super.initState();
emailController = TextEditingController();
passwordController = TextEditingController();
retypePasswordController = TextEditingController();
}

@override
void dispose() {
emailController.dispose();
passwordController.dispose();
retypePasswordController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Form(
key: context.read().registerFormKey,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
‘Register a new User’,
style: headingStyle,
),
const SizedBoxH30(),
TextFormField(
validator: validateEmail,
controller: emailController,
decoration: formDecoration(‘Email’, Icons.mail),
),
const SizedBoxH10(),
TextFormField(
validator: validatePassword,
controller: passwordController,
decoration: formDecoration(‘Password’, Icons.lock),
),
const SizedBoxH10(),
TextFormField(
validator: validatePassword,
controller: retypePasswordController,
decoration: formDecoration(‘Re-Type Password’, Icons.lock),
),
const SizedBoxH20(),
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),
),
onPressed: () {
context.read().registerNewUser(
emailController.text.trim(),
passwordController.text.trim(),
);

          },
          child: const Text('Register'),
        ),
      ],
    ),
  ),
);

}
}

/////////////////////////////////////////////////////////////////////////////////
class UserManagementViewModel with ChangeNotifier {
final registerFormKey = GlobalKey();
final loginFormKey = GlobalKey();

BackendlessUser? _currentUser;
BackendlessUser? get currentUser => _currentUser;

void setCurrentUserNull() {
_currentUser = null;
}

bool _userExists = false;
bool get userExists => _userExists;

set userExists(bool value) {
_userExists = value;
notifyListeners();
}

bool _showUserProgress = false;
bool get showUserProgress => _showUserProgress;

String _userProgressText = ‘’;
String get userProgressText => _userProgressText;

void registerNewUser(
BuildContext context, {
required String email,
required String password,
}) {
FocusManager.instance.primaryFocus?.unfocus();

if (registerFormKey.currentState?.validate() ?? false) {
  BackendlessUser user = BackendlessUser()
    ..email = email
    ..password = password;
  //show the progress
  _showUserProgress = true;
  _userProgressText = 'Busy registering new user.....please wait... ';
  notifyListeners();
  //
  Backendless.userService.register(user).then((user) {
    print('${user!.email} is successfully registered.');
    //take to login
    Navigator.popAndPushNamed(context, RouteManager.loginPage);
  }).onError((error, stackTrace) {
    print('${error.toString()}');
  });
  _showUserProgress = false;
  notifyListeners();
}

}

void loginUser(BuildContext context,
{required String email, required String password}) {
FocusManager.instance.primaryFocus?.unfocus();
if (loginFormKey.currentState?.validate() ?? false) {
//show the progress
_showUserProgress = true;
_userProgressText = ‘Busy logging in user…please wait… ‘;
notifyListeners();
Backendless.userService.login(email, password, true).then((user) {
print(’${user!.email} logged in’);
//take user to login page
Navigator.popAndPushNamed(context, RouteManager.noteListPage);
//
}).onError((error, stackTrace) {
print(’${error.toString()}’);
});
_showUserProgress = false;
notifyListeners();
}
}

void resetPasswordInUI(BuildContext context, {required String email}) {
_showUserProgress = true;
_userProgressText = ‘Busy sending reset instructions…please wait… ‘;
notifyListeners();
Backendless.userService.restorePassword(email).then((value) {
print(‘Password reset instructions send via email’);
}).onError((error, stackTrace) {
if (kDebugMode) {
print(’${error.toString()}’);
}
});
_showUserProgress = false;
notifyListeners();
}

void logoutUserInUI(BuildContext context) {
//show the pregress
_showUserProgress = true;
_userProgressText = ‘Busy signing you out please wait…please wait… ‘;
notifyListeners();
//
Backendless.userService.logout().then((value) {
//take user to login page
Navigator.popAndPushNamed(context, RouteManager.loginPage);
//
print(‘Successfully logged out!’);
}).onError((error, stackTrace) {
if (kDebugMode) {
print(’${error.toString()}’);
}
});
_showUserProgress = false;
notifyListeners();
}
}

That’s my code but I cannot register a new user on backendless

if you believe the problem is in our SDK/API, please create the smallest possible program that reproduces the issue. As a part of support, we will be happy to assist with the functionality provided by Backendless, but we cannot debug or review your complete program listings.

Regards,
Mark

I have done that but it’s not working

Can you share the simple program? It should be as simple as:

  1. Init app
  2. Register user (use hard-coded values).