Back

Unable create new user in appwrite from flutter

  • 2
  • Flutter
  • Web
  • Databases
  • Android
  • General
joeyouss
14 Apr, 2023, 16:01

Hi -thank you for sharing

TL;DR
The user is unable to create a new user in the Appwrite app from Flutter. They have tried different URLs, but none of them are working. The issue may be that the user is not catching the error in their code. However, even when there are no errors, the Appwrite dashboard does not show the user being added. The solution is to use the IP address "10.0.2.2" instead of "localhost" when using an Android emulator. This IP address refers to the host machine where Appwrite is running. The code shared in the support thread includes the Flutter code for the homepage and authentication, as well
Jebin shaju
14 Apr, 2023, 16:02
joeyouss
14 Apr, 2023, 16:02

Let me take a look

Jebin shaju
14 Apr, 2023, 16:04
TypeScript
import 'package:flutter/material.dart';

import 'homepage.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Todo App',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const Homepage(),
    );
  }
}

Main.dart

Jebin shaju
14 Apr, 2023, 16:04

auth.dart

TypeScript
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('http://localhost/v1')
    .setProject('64392f2ec924b428ae8c')
    .setSelfSigned(
        status: true); // For self signed certificates, only use for development

//create an user account

Account account = Account(client);

Future createUser() async {
  final user = await account.create(
      userId: ID.unique(),
      email: 'me@appwrite.io',
      password: 'password',
      name: 'My Name');
  print("New User created");
}
Jebin shaju
14 Apr, 2023, 16:05

homepage.dart

TypeScript
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:todo_app/auth.dart';

class Homepage extends StatelessWidget {
  const Homepage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
      child: TextButton(
        child: const Text("Create User"),
        onPressed: () {
          createUser();
        },
      ),
    ));
  }
}
Jebin shaju
14 Apr, 2023, 16:11

@Steven please help

Drake
14 Apr, 2023, 16:17

your problem is that localhost refers to the current device so your android emulator will try to connect to itself rather than your host machine where Appwrite is running. On an android emulator, instead of localhost, you can use 10.0.2.2, a special IP that refers to the host machine.

Maniac_Fighter
14 Apr, 2023, 16:19

localhost wouldn't work as it would try to connect to itself rather than your computer host you need to use this http://{YOUR_COMUPTER_IPV4_ADDRESS}:{PORT}}/v1

Jebin shaju
14 Apr, 2023, 16:19

Ok thanks 🙏

Jebin shaju
14 Apr, 2023, 16:19

Let me check

joeyouss
14 Apr, 2023, 16:27

Can we close this issue if its resolved @Jebin shaju https://github.com/appwrite/sdk-for-flutter/issues/142

Jebin shaju
14 Apr, 2023, 16:40

no, now no errror occur but the appwrite dashboard doesnot show user being added

Drake
14 Apr, 2023, 16:52

There's gotta be an error...maybe you're not catching it in your code

Jebin shaju
14 Apr, 2023, 16:52

yes i think so

Jebin shaju
14 Apr, 2023, 16:52

but i have 28 request to the app write

Drake
14 Apr, 2023, 16:53

maybe from the console or something

Jebin shaju
14 Apr, 2023, 16:54

http://10.0.2.2/v1 isnt this the ip i should be using

Jebin shaju
14 Apr, 2023, 16:54

when using an emulator

Jebin shaju
14 Apr, 2023, 17:18
Drake
14 Apr, 2023, 17:28

sure...or maybe https://10.0.2.2/v1

Jebin shaju
14 Apr, 2023, 17:30

both are not working

Jebin shaju
14 Apr, 2023, 17:39

any ways thanks for your support, really like your support team

Drake
14 Apr, 2023, 18:11

what's the error?

Drake
14 Apr, 2023, 18:11

are you sure you're looking in the right project?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more