appwrite / sdk-for-flutter

[READ-ONLY] Official Appwrite Flutter SDK πŸ’™

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug Report: AppwriteException: null, Connection refused (0)

jebinshaju opened this issue Β· comments

πŸ‘Ÿ Reproduction steps

When i was trying to create a todo app with flutter and appwrite , i was not able to register new users .

main.dart

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(),
    );
  }
}

auth.dart

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");
}

homepage.dart

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();
        },
      ),
    ));
  }
}

error i am getting

Launching lib\main.dart on Android SDK built for x86 in debug mode...
main.dart:1
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:61863/095xhGqFJ90=/ws
E/flutter ( 5774): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: AppwriteException: null, Connection refused (0)
E/flutter ( 5774): #0      ClientIO.call
client_io.dart:381
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774): #1      Account.create
account.dart:53
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774): #2      createUser
auth.dart:14
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774):

πŸ‘ Expected behavior

It should have created a new user and report it in the appwrite page

πŸ‘Ž Actual Behavior

image

Error i am getting

Launching lib\main.dart on Android SDK built for x86 in debug mode...
main.dart:1
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:61863/095xhGqFJ90=/ws
E/flutter ( 5774): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: AppwriteException: null, Connection refused (0)
E/flutter ( 5774): #0      ClientIO.call
client_io.dart:381
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774): #1      Account.create
account.dart:53
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774): #2      createUser
auth.dart:14
E/flutter ( 5774): <asynchronous suspension>
E/flutter ( 5774):

🎲 Appwrite version

Version 2.0.x

πŸ’» Operating system

Windows

🧱 Your Environment

No response

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

Hi - the solution to this was given on our community discord to you <3 Please close the issue if this Bug has been resolved.

bug isnt fixed , i tryied changing the address from localhost to 10.0.2.2 but it doesnt work ie it doesnt add user to appwrite, but it shows that responses have been made.