• Stars
    star
    364
  • Rank 117,101 (Top 3 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Appwrite Flutter SDK

pub package License Version Build Status Twitter Account Discord

This SDK is compatible with Appwrite server version 1.3.x. For older versions, please check previous releases.

Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs

Appwrite

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  appwrite: ^9.0.0

You can install packages from the command line:

flutter pub add appwrite

Getting Started

Add your Flutter Platform

To init your SDK and start interacting with Appwrite services, you need to add a new Flutter platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before, and click the 'Add Platform' button.

From the options, choose to add a new Flutter platform and add your app credentials. Appwrite Flutter SDK currently supports building apps for Android, iOS, Linux, Mac OS, Web and Windows.

If you are building your Flutter application for multiple devices, you have to follow this process for each different device.

Android

For Android first add your app name and package name, Your package name is generally the applicationId in your app-level build.gradle file. By registering your new app platform, you are allowing your app to communicate with the Appwrite API.

In order to capture the Appwrite OAuth callback url, the following activity needs to be added inside the <application> tag, along side the existing <activity> tags in your AndroidManifest.xml. Be sure to replace the [PROJECT_ID] string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in the console.

<manifest ...>
    ....
    <application ...>
        ....
        <!-- Add this inside the <application> tag, along side the existing <activity> tags -->
        <activity android:exported="true" android:name="com.linusu.flutter_web_auth_2.CallbackActivity" >
            <intent-filter android:label="flutter_web_auth_2">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="appwrite-callback-[PROJECT_ID]" />
            </intent-filter>
        </activity>
    </application>
</manifest>

iOS

For iOS first add your app name and Bundle ID, You can find your Bundle Identifier in the General tab for your app's primary target in Xcode.

The Appwrite SDK uses ASWebAuthenticationSession on iOS 12+ and SFAuthenticationSession on iOS 11 to allow OAuth authentication. You have to change your iOS Deployment Target in Xcode to be iOS >= 11 to be able to build your app on an emulator or a real device.

  1. In Xcode, open Runner.xcworkspace in your app's ios folder.
  2. To view your app's settings, select the Runner project in the Xcode project navigator. Then, in the main view sidebar, select the Runner target.
  3. Select the General tab.
  4. In Deployment Info, 'Target' select iOS 11.0

Linux

For Linux add your app name and package name, Your package name is generally the name in your pubspec.yaml file. If you cannot find the correct package name, run the application in linux, and make any request with proper exception handling, you should get the application ID needed to add in the received error message.

Mac OS

For Mac OS add your app name and Bundle ID, You can find your Bundle Identifier in the General tab for your app's primary target in Xcode.

Web

Appwrite 0.7, and the Appwrite Flutter SDK 0.3.0 have added support for Flutter Web. To build web apps that integrate with Appwrite successfully, all you have to do is add a web platform on your Appwrite project's dashboard and list the domain your website will use to allow communication to the Appwrite API.

For web in order to capture the OAuth2 callback URL and send it to the application using JavaScript postMessage(), you need to create an html file inside ./web folder of your Flutter project. For example auth.html with the following content.

<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please
close the window.
<script>
  window.opener.postMessage({
    'flutter-web-auth-2': window.location.href
  }, window.location.origin);
  window.close();
</script>

Redirection URL passed to the authentication service must be the same as the URL on which the application is running (schema, host, port if necessary) and the path must point to created HTML file, /auth.html in this case. The callbackUrlScheme parameter of the authenticate() method does not take into account, so it is possible to use a schema for native platforms in the code.

Flutter Web Cross-Domain Communication & Cookies

While running Flutter Web, make sure your Appwrite server and your Flutter client are using the same top-level domain and the same protocol (HTTP or HTTPS) to communicate. When trying to communicate between different domains or protocols, you may receive HTTP status error 401 because some modern browsers block cross-site or insecure cookies for enhanced privacy. In production, Appwrite allows you set multiple custom-domains for each project.

Windows

For Windows add your app name and package name, Your package name is generally the name in your pubspec.yaml file. If you cannot find the correct package name, run the application in windows, and make any request with proper exception handling, you should get the application id needed to add in the received error message.

Init your SDK

Initialize your SDK with your Appwrite server API endpoint and project ID, which can be found in your project settings page.

import 'package:appwrite/appwrite.dart';

void main() {
  Client client = Client();

  client
    .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint
    .setProject('5e8cf4f46b5e8') // Your project ID
    .setSelfSigned() // Use only on dev mode with a self-signed SSL cert
  ;
}

Before starting to send any API calls to your new Appwrite instance, make sure your Android or iOS emulators has network access to the Appwrite server hostname or IP address.

When trying to connect to Appwrite from an emulator or a mobile device, localhost is the hostname for the device or emulator and not your local Appwrite instance. You should replace localhost with your private IP as the Appwrite endpoint's hostname. You can also use a service like ngrok to proxy the Appwrite API.

Make Your First Request

Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.

// Register User
Account account = Account(client);
final user = await account
  .create(
    userId: ID.unique(),
    email: '[email protected]',
    password: 'password',
    name: 'My Name'
  );

Full Example

import 'package:appwrite/appwrite.dart';

void main() {
  Client client = Client();


  client
    .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint
    .setProject('5e8cf4f46b5e8') // Your project ID
    .setSelfSigned() // Use only on dev mode with a self-signed SSL cert
    ;


  // Register User
  Account account = Account(client);

  final user = await account
    .create(
      userId: ID.unique(),
      email: '[email protected]',
      password: 'password',
      name: 'My Name'
    );
}

Error Handling

The Appwrite Flutter SDK raises AppwriteException object with message, type, code and response properties. You can handle any errors by catching AppwriteException and present the message to the user or handle it yourself based on the provided error information. Below is an example.

Account account = Account(client);

try {
  final user = await account.create(userId: ID.unique(), email: โ€˜email@example.comโ€™,password: โ€˜passwordโ€™, name: โ€˜nameโ€™);
  print(user.toMap());
} on AppwriteException catch(e) {
  //show message to user or do other operation based on error as required
  print(e.message);
}

Learn more

You can use the following resources to learn more and get help

Contribution

This library is auto-generated by Appwrite custom SDK Generator. To learn more about how you can help us improve this SDK, please check the contribution guide before sending a pull-request.

License

Please see the BSD-3-Clause license file for more information.

More Repositories

1

appwrite

Your backend, minus the hassle.
TypeScript
43,403
star
2

sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK ๐Ÿ’™ โš›๏ธŽ
TypeScript
2,942
star
3

awesome-appwrite

Carefully curated list of awesome Appwrite resources ๐Ÿ’ช
954
star
4

pink

Pink. Appwrite's official framework agnostic design system ๐ŸŽจ ๐Ÿฉท
HTML
442
star
5

console

The Console that makes Appwrite tick from the browser ๐Ÿ–ฅ
Svelte
319
star
6

sdk-for-web

[READ-ONLY] Official Appwrite Web SDK ๐Ÿงก
TypeScript
281
star
7

sdk-generator

Generating SDKs for multiple programming languages and platforms โš™๏ธ
Twig
272
star
8

sdk-for-python

[READ-ONLY] Official Appwrite Python SDK ๐Ÿ
Python
221
star
9

sdk-for-node

[READ-ONLY] Official Appwrite Node.js SDK ๐ŸŸข
TypeScript
205
star
10

demo-todo-with-react

A basic demo example for integrating between Appwrite & React JS ๐Ÿ’™
JavaScript
201
star
11

website

The Appwrite website, docs and blog ๐Ÿ 
Svelte
188
star
12

sdk-for-php

[READ-ONLY] Official Appwrite PHP SDK ๐Ÿ˜
PHP
140
star
13

demos-for-functions

Demo for Appwrite cloud functions in multiple coding languages โšก๏ธ ๐ŸŒฉ
Kotlin
121
star
14

playground-for-flutter

Simple examples that help you get started with Appwrite + Flutter (=โค๏ธ)
C++
121
star
15

templates

Templates for Appwrite Functions โšก๏ธ๐ŸŒฉ๏ธ
JavaScript
117
star
16

demo-todo-with-vue

A basic demo example for integrating between Appwrite & Vue JS ๐Ÿ’š
Vue
116
star
17

sdk-for-dart

[READ-ONLY] Official Appwrite Dart SDK ๐Ÿ’™
Dart
112
star
18

sdk-for-android

[READ-ONLY] Official Appwrite Android SDK ๐Ÿ’š ๐Ÿค–
Kotlin
108
star
19

demo-todo-with-svelte

A basic demo example for integrating between Appwrite & Svelte๐Ÿงก
Svelte
107
star
20

playground-for-web

Simple examples that help you get started with Appwrite + Web (=โค๏ธ)
HTML
99
star
21

sdk-for-apple

[READ-ONLY] Official Appwrite SDK for Apple Devices ๐ŸŽ
Swift
99
star
22

sdk-for-dotnet

[READ-ONLY] Official Appwrite .NET SDK
C#
94
star
23

sdk-for-cli

[READ-ONLY] Official Appwrite CLI >_
JavaScript
89
star
24

demos-for-react

Demos and tutorials for getting started with Appwrite + React JS
JavaScript
89
star
25

docs

The official https://appwrite.io/docs documentation ๐Ÿ“
HTML
84
star
26

sdk-for-kotlin

[READ-ONLY] Official Appwrite Kotlin SDK ๐Ÿ’™๐Ÿงก
Kotlin
77
star
27

dynamic-links

Implement Dynamic Links with Appwrite Functions!
HTML
75
star
28

sdk-for-svelte

Appwrite SDK for Svelte ๐Ÿงก โš ๏ธ Warning - this SDK was designed to support Appwrite 0.9 and is not compatible with the latest Appwrite versions. We are planing to refactor it as part of the SDK Generator for better support and maintenance.
Svelte
74
star
29

demo-almost-netflix-for-flutter

A Netflix clone built with @appwrite + @flutter
Dart
73
star
30

sdk-for-deno

[READ-ONLY] Official Appwrite Deno SDK ๐Ÿฆ•
TypeScript
71
star
31

demo-todo-with-angular

A basic demo example for integrating between Appwrite & Angular โค๏ธ
TypeScript
67
star
32

playground-for-android

Simple examples that help you get started with Appwrite + Android (=โค๏ธ)
Kotlin
66
star
33

sdk-for-go

[READ-ONLY] Official Appwrite GO SDK
Go
65
star
34

lite

A single container version of Appwrite with minimum must have features โš–๏ธ
Shell
65
star
35

php-clamav

ClamAV network and pipe client for PHP
PHP
63
star
36

playground-for-node

Simple examples that help you get started with Appwrite + Node.js (=โค๏ธ)
JavaScript
63
star
37

playground-for-python

Simple examples that help you get started with Appwrite + Python (=โค๏ธ)
Python
62
star
38

realtime-1-million

Learn how we built and tested our realtime server to 1M+ concurrent connections
Shell
59
star
39

sdk-for-ruby

[READ-ONLY] Official Appwrite Ruby SDK ๐Ÿ’Ž ๐Ÿ”ด
Ruby
58
star
40

demo-todo-with-nextjs

A basic demo example for integrating between Appwrite & Next.js ๐Ÿ’™
TypeScript
55
star
41

rfc

Architectural and new features proposals and designs for Appwrite ๐Ÿ“–
54
star
42

docker-clamav

ClamAV docker image with auto database updates
Shell
50
star
43

docker-smtp

SMTP server docker container for sending emails.
Dockerfile
48
star
44

assistant

Appwrite's AI assistant ๐Ÿง 
JavaScript
48
star
45

sdk-for-swift

[READ-ONLY] Official Appwrite Swift SDK ๐Ÿฆ…๐ŸŽ
Swift
47
star
46

demos-for-vue

Demos and tutorials for getting started with Appwrite + Vue.js
Vue
44
star
47

runtimes

Appwrite configuration for Cloud Function runtimes settings ๐ŸŒฉ
PHP
42
star
48

30daysofappwrite

Landing Page for 30 Days of Appwrite
Vue
41
star
49

techscrunch

Very relAIble open source alternative for TechCrunch
Svelte
40
star
50

builtwith

Explore popular projects built with Appwrite ๐Ÿ”
TypeScript
40
star
51

demo-quiz-with-flutter

A basic demo example for integrating between Appwrite & Flutter ๐Ÿ’™
Dart
40
star
52

playground-for-dart

Simple examples that help you get started with Appwrite + Dart (=โค๏ธ) as an Appwrite server-side integration.
Dart
40
star
53

integration-for-gitpod

Shell
39
star
54

hacktoberfest

๐Ÿก Home to Appwrite's Hacktoberfest Landing Page
Svelte
39
star
55

playground-for-apple-swiftui

Simple examples that help you get started with Appwrite + Apple with SwiftUI (=โค๏ธ)
Swift
39
star
56

demo-todo-with-flutter

A basic demo example for integrating between Appwrite & Flutter ๐Ÿ’™
Dart
38
star
57

docker-mariadb

MariaDB container with Appwrite server DB schema and tables initialized and ready to use for fresh installations.
Dockerfile
37
star
58

docker-resque-ui

Docker container for Resque web UI
Dockerfile
36
star
59

demos-for-svelte

Demos and tutorials for getting started with Appwrite + Svelte
JavaScript
36
star
60

playground-for-php

Simple examples that help you get started with Appwrite + PHP (=โค๏ธ)
PHP
35
star
61

docker-flutter

Flutter docker image for Appwrite CI
Dockerfile
33
star
62

install

CLI tool for easy installation of a self-hosted Appwrite server
PHP
32
star
63

docker-telegraf

Telegraf Docker image, pre-configured for Appwrite server setup.
Dockerfile
31
star
64

demos-for-astro

Astro
31
star
65

playground-for-deno

Simple examples that help you get started with Appwrite + Deno (=โค๏ธ)
TypeScript
30
star
66

functions-starter

Java
30
star
67

demo-job-portal-with-apple

A basic demo example for integrating between Appwrite & Apple (=โค๏ธ)
Swift
29
star
68

playground-for-dotnet

Simple examples that help you get started with Appwrite + .NET (=โค๏ธ)
C#
29
star
69

demo-almost-netflix-for-web

A Netflix clone built with @appwrite + @vuejs + @nuxt
Vue
29
star
70

playground-for-swift

Simple examples that help you get started with Appwrite + Swift for Server (=โค๏ธ)
Swift
29
star
71

demos-for-angular

Demos and tutorials for getting started with Appwrite + Angular JS
TypeScript
29
star
72

playground-for-ruby

Simple examples that help you get started with Appwrite + Ruby (=โค๏ธ)
Ruby
27
star
73

playground-for-apple-uikit

Simple examples that help you get started with Appwrite + iOS with UIKit (=โค๏ธ)
Swift
27
star
74

docker-influxdb

InfluxDB Docker image, pre-configured for Appwrite server setup.
Shell
26
star
75

playground-for-kotlin

Simple examples that help you get started with Appwrite + Kotlin (=โค๏ธ)
Kotlin
25
star
76

demo-watertracker-with-flutter

Dart
25
star
77

docker-altair

GraphQL client explorer packaged as a docker container ๐Ÿ•ธ
JavaScript
24
star
78

docker-mailcatcher

MailCatcher for catching mail content during development
Dockerfile
22
star
79

sdk-for-rust

[READ-ONLY] Official Appwrite Rust SDK โš™๏ธ
22
star
80

setup-for-appwrite

22
star
81

docker-requestcatcher

RequestCatcher for catching requests response during development
Dockerfile
22
star
82

integration-for-digitalocean

Appwrite integration for DigitalOcean 1-Click Marketplace
Shell
21
star
83

demo-quiz-with-android

Kotlin
20
star
84

benchmarks

The Appwrite laboratory for benchmarks and experiments ๐Ÿงช ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿฅฝ
20
star
85

docker-base

Appwrite base image
Dockerfile
18
star
86

demo-almost-netflix-for-android

Kotlin
17
star
87

docker-swagger

Swagger UI Docker image, pre-configured for Appwrite server setup
16
star
88

.github

16
star
89

demo-getstarted-with-android

Kotlin
15
star
90

sdk-for-console

TypeScript
15
star
91

demo-almost-netflix-for-apple

Swift
14
star
92

playground-for-react-native

Simple examples that help you get started with Appwrite + React Native (=โค๏ธ)
JavaScript
12
star
93

sdk-for-node-cli

JavaScript
11
star
94

snapwrite

A tool to convert code snippets into beautiful Appwrite-themed social-media images
Svelte
9
star
95

makers

Makers of Appwrite
Svelte
7
star
96

playground-for-rust

6
star
97

starter-for-vue

Appwrite's starter kit for Vue.js ๐Ÿ‘ฉโ€๐Ÿ’ป
4
star
98

getting-started-projects

TypeScript
4
star
99

demos-for-apple

Demos and tutorials for getting started with Appwrite + Apple
Swift
4
star
100

incidents

Details of incidents that occurred in Appwrite Cloud
4
star