### Full Example: Initialize and Create User Source: https://github.com/appwrite/sdk-for-flutter/blob/main/README.md A complete example demonstrating how to initialize the Appwrite client and create a new user account. ```dart Client client = Client().setProject('>'); Account account = Account(client); User user = await account.create( userId: ID.unique(), email: 'email@example.com', password: 'password', name: 'Walter O'Brien' ); ``` -------------------------------- ### Update Transaction Example Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/update-transaction.md Demonstrates how to initiate an update for a transaction. The `commit` and `rollback` parameters are optional and control the transaction's final state. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); Transaction result = await databases.updateTransaction( transactionId: '', commit: false, // optional rollback: false, // optional ); ``` -------------------------------- ### Get File Preview Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/get-file-preview.md This snippet demonstrates how to retrieve a file preview. It shows how to download the preview as bytes and then write it to a file. It also includes an example of how to use `FutureBuilder` to display the image preview directly in a Flutter application. This method works for both public and private files; for private files, ensure the user is logged in. ```APIDOC ## Get File Preview ### Description Retrieves a preview of a file. This can be used to download the file content or display it directly, for example, as an image. ### Method `storage.getFilePreview` ### Parameters #### Path Parameters - **bucketId** (string) - Required - Bucket ID. - **fileId** (string) - Required - File ID. #### Query Parameters - **width** (integer) - Optional - Preview width, in pixels. Default is 0. - **height** (integer) - Optional - Preview height, in pixels. Default is 0. - **gravity** (ImageGravity) - Optional - Image cropping gravity. Default is `ImageGravity.center`. - **quality** (integer) - Optional - Preview quality, in percentage. Default is 100. - **borderWidth** (integer) - Optional - Preview border width, in pixels. Default is 0. - **borderColor** (string) - Optional - Preview border color. Default is hex color. Example: '#FFFFFF'. - **borderRadius** (integer) - Optional - Preview border radius, in pixels. Default is 0. - **opacity** (integer) - Optional - Preview opacity, in percentage. Default is 100. - **rotation** (integer) - Optional - Preview rotation degrees. Default is 0. - **background** (string) - Optional - Preview background color. Default is hex color. Example: '#000000'. - **output** (ImageFormat) - Optional - Preview output format. Default is `ImageFormat.jpg`. - **token** (string) - Optional - Security token. Use this token to generate a URL for the preview. If the file is public, the token is not required. ### Request Example ```dart Uint8List bytes = await storage.getFilePreview( bucketId: '', fileId: '', width: 0, // optional height: 0, // optional gravity: enums.ImageGravity.center, // optional quality: -1, // optional borderWidth: 0, // optional borderColor: '', // optional borderRadius: 0, // optional opacity: 0, // optional rotation: -360, // optional background: '', // optional output: enums.ImageFormat.jpg, // optional token: '', // optional ); final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes); ``` ### Response #### Success Response (200) Returns the file preview as `Uint8List`. #### Response Example ```dart // For displaying image preview FutureBuilder( future: storage.getFilePreview( bucketId:'' , fileId:'' , width:0 , // optional height:0 , // optional gravity: enums.ImageGravity.center, // optional quality:-1 , // optional borderWidth:0 , // optional borderColor:'' , // optional borderRadius:0 , // optional opacity:0 , // optional rotation:-360 , // optional background:'' , // optional output: enums.ImageFormat.jpg, // optional token:'' , // optional ), builder: (context, snapshot) { return snapshot.hasData && snapshot.data != null ? Image.memory(snapshot.data) : CircularProgressIndicator(); } ); ``` ``` -------------------------------- ### Install Appwrite Package via Flutter CLI Source: https://github.com/appwrite/sdk-for-flutter/blob/main/README.md Use the flutter pub add command to install the Appwrite package directly into your Flutter project. ```bash flutter pub add appwrite ``` -------------------------------- ### Get a File from Storage Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/get-file.md Retrieves a specific file from a bucket. Ensure you have initialized the Appwrite client and Storage service with your project details and endpoint. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Storage storage = Storage(client); File result = await storage.getFile( bucketId: '', fileId: '', ); ``` -------------------------------- ### Get Current User Account Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/get.md Use this snippet to fetch the details of the currently authenticated user. Ensure your client is initialized with your project's endpoint and ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); User result = await account.get(); ``` -------------------------------- ### Get Session by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/get-session.md Retrieves the details of a specific user session using its ID. Ensure the client is initialized with your project's endpoint and ID, and the Account service is instantiated. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Session result = await account.getSession( sessionId: '', ); ``` -------------------------------- ### Get User Preferences Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/get-prefs.md Retrieves the preferences object for the currently logged-in user. Ensure you have initialized the Appwrite client and Account service before calling this method. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Preferences result = await account.getPrefs(); ``` -------------------------------- ### Get Team Membership using Appwrite SDK for Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/teams/get-membership.md This snippet demonstrates how to initialize the Appwrite client, instantiate the Teams service, and retrieve a specific team membership by its ID. Ensure you replace placeholders with your actual project details, region, team ID, and membership ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Teams teams = Teams(client); Membership result = await teams.getMembership( teamId: '', membershipId: '', ); ``` -------------------------------- ### Get Team Preferences in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/teams/get-prefs.md Initializes the Appwrite client and retrieves the preferences for a given team ID. Ensure you replace placeholders with your actual API endpoint, project ID, and team ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.org/v1') // Your API Endpoint .setProject(''); // Your project ID Teams teams = Teams(client); Preferences result = await teams.getPrefs( teamId: '', ); ``` -------------------------------- ### Get MFA Recovery Codes in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/get-mfa-recovery-codes.md Initializes the Appwrite client and account, then calls the getMFARecoveryCodes method to retrieve recovery codes. Ensure you have set your API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); MfaRecoveryCodes result = await account.getMFARecoveryCodes(); ``` -------------------------------- ### List Files in a Bucket Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/list-files.md Initializes the Appwrite client and demonstrates how to list all files in a specified bucket. Includes optional parameters for searching and controlling total count. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Storage storage = Storage(client); FileList result = await storage.listFiles( bucketId: '', queries: [], // optional search: '', // optional total: false, // optional ); ``` -------------------------------- ### Execute a GraphQL Query Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/graphql/query.md This snippet demonstrates how to initialize the Appwrite client, set up the GraphQL service, and execute a basic query. Ensure you replace placeholder values with your actual API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Graphql graphql = Graphql(client); Any result = await graphql.query( query: {}, ); ``` -------------------------------- ### Get Transaction by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/get-transaction.md Fetches a transaction using its unique identifier. This is a direct method call provided by the TablesDB service. ```APIDOC ## Get Transaction ### Description Retrieves a specific transaction using its ID. ### Method `getTransaction` ### Parameters #### Path Parameters - **transactionId** (string) - Required - The unique identifier of the transaction to retrieve. ### Request Example ```dart Transaction result = await tablesDB.getTransaction( transactionId: '', ); ``` ### Response #### Success Response (200) - **transaction** (Transaction) - The retrieved transaction object. #### Response Example ```json { "$id": "", "transaction": { "amount": 1000, "currency": "USD", "status": "completed", "createdAt": "2023-10-27T10:00:00.000+00:00", "updatedAt": "2023-10-27T10:05:00.000+00:00" } } ``` ``` -------------------------------- ### List Account Logs Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/list-logs.md Initializes the Appwrite client and account, then calls the listLogs method. Ensure you replace placeholders with your actual API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); LogList result = await account.listLogs( queries: [], // optional total: false, // optional ); ``` -------------------------------- ### Get Transaction by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/get-transaction.md Retrieves a specific transaction using its ID. Ensure your client is initialized with your project's endpoint and ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); Transaction result = await databases.getTransaction( transactionId: '', ); ``` -------------------------------- ### Create Push Target Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-push-target.md This snippet demonstrates how to initialize the Appwrite client and create a push target using the Account service. Ensure you replace placeholders with your actual API endpoint, project ID, and target details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Target result = await account.createPushTarget( targetId: '', identifier: '', providerId: '', // optional ); ``` -------------------------------- ### List Transactions in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/list-transactions.md Demonstrates how to fetch a list of transactions. Ensure you have initialized the Appwrite client and databases service with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); TransactionList result = await databases.listTransactions( queries: [], // optional ); ``` -------------------------------- ### Create User and Session Source: https://github.com/appwrite/sdk-for-flutter/blob/main/example/README.md Create a new user with unique ID, email, password, and name. Then, create an email session for the user. ```dart Account account = Account(client); final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien"); final session = await account.createEmailSession(email: 'me@appwrite.io', password: 'password'); ``` -------------------------------- ### Get Current Locale - Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/locale/get.md Fetches the current locale settings for the project. Ensure the client is initialized with your project's endpoint and ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Locale locale = Locale(client); Locale result = await locale.get(); ``` -------------------------------- ### Get Document by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/get-document.md Retrieves a specific document from a collection using its ID. Ensure the client and database services are initialized with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); Document result = await databases.getDocument( databaseId: '', collectionId: '', documentId: '', queries: [], // optional transactionId: '', // optional ); ``` -------------------------------- ### List Documents in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/list-documents.md Initializes the Appwrite client and demonstrates fetching a list of documents from a specified database and collection. Ensure you replace placeholders with your actual project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); DocumentList result = await databases.listDocuments( databaseId: '', collectionId: '', queries: [], // optional transactionId: '', // optional total: false, // optional ttl: 0, // optional ); ``` -------------------------------- ### Get Team by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/teams/get.md Retrieves a specific team using its unique ID. Ensure you have initialized the Appwrite client and Teams service with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Teams teams = Teams(client); Team result = await teams.get( teamId: '', ); ``` -------------------------------- ### Get Presence by ID - Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/presences/get.md Use this snippet to fetch the presence details of a specific user. Ensure you have initialized the Appwrite client and the Presences service. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Presences presences = Presences(client); Presence result = await presences.get( presenceId: '', ); ``` -------------------------------- ### Initialize Appwrite Client Source: https://github.com/appwrite/sdk-for-flutter/blob/main/example/README.md Initialize the Appwrite client with your endpoint, project ID, and optionally set self-signed certificates. Remove setSelfSigned() in production. ```dart Client client = Client(); client .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint .setProject('5e8cf4f46b5e8') // Your project ID .setSelfSigned() // Remove in production ; ``` -------------------------------- ### List Supported Languages Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/locale/list-languages.md Initializes the Appwrite client and then uses the Locale service to fetch a list of all supported languages. Ensure you replace placeholders with your actual project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Locale locale = Locale(client); LanguageList result = await locale.listLanguages(); ``` -------------------------------- ### Download Screenshot as Bytes Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-screenshot.md Demonstrates how to download a screenshot of a given URL as a Uint8List. This method allows for various customization options for the screenshot. The downloaded bytes can then be saved to a file. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; import 'dart:io'; import 'package:flutter/widgets.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Avatars avatars = Avatars(client); // Downloading file Future downloadScreenshot() async { Uint8List bytes = await avatars.getScreenshot( url: 'https://example.com', headers: { "Authorization": "Bearer token123", "X-Custom-Header": "value" }, // optional viewportWidth: 1920, // optional viewportHeight: 1080, // optional scale: 2, // optional theme: enums.BrowserTheme.dark, // optional userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15', // optional fullpage: true, // optional locale: 'en-US', // optional timezone: enums.Timezone.africaAbidjan, // optional latitude: 37.7749, // optional longitude: -122.4194, // optional accuracy: 100, // optional touch: true, // optional permissions: [enums.BrowserPermission.geolocation, enums.BrowserPermission.notifications], // optional sleep: 3, // optional width: 800, // optional height: 600, // optional quality: 85, // optional output: enums.ImageFormat.jpeg, // optional ); final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes); } ``` -------------------------------- ### Get a Row by ID Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/get-row.md Retrieves a single row from a specified table using its unique ID. Ensure you have initialized the Client and TablesDB services with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID TablesDB tablesDB = TablesDB(client); Row result = await tablesDB.getRow( databaseId: '', tableId: '', rowId: '', queries: [], // optional transactionId: '', // optional ); ``` -------------------------------- ### Create Operations in TablesDB Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/create-operations.md This snippet demonstrates how to initialize the Appwrite client and use the `createOperations` method to add a new record to a table. Ensure you replace placeholders like '', '', '', '', '', and '' with your actual values. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID TablesDB tablesDB = TablesDB(client); Transaction result = await tablesDB.createOperations( transactionId: '', operations: [ { "action": "create", "databaseId": "", "tableId": "", "rowId": "", "data": { "name": "Walter O'Brien" } } ], // optional ); ``` -------------------------------- ### Update Phone Verification Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/update-phone-verification.md Updates the phone verification status for a user. This method requires the user's ID and a secret token previously obtained, for example, through the `createPhoneVerification` method. ```APIDOC ## POST /account/phone/verification ### Description Updates the phone verification status for a user. This method requires the user's ID and a secret token previously obtained, for example, through the `createPhoneVerification` method. ### Method POST ### Endpoint /account/phone/verification ### Parameters #### Request Body - **userId** (string) - Required - The ID of the user to verify. - **secret** (string) - Required - The secret token received for phone verification. ### Request Example ```json { "userId": "", "secret": "" } ``` ### Response #### Success Response (200) - **token** (string) - The updated verification token. #### Response Example ```json { "token": "" } ``` ``` -------------------------------- ### Create User Account Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create.md Use this snippet to create a new user account. Ensure you have initialized the Appwrite client with your endpoint and project ID. The userId, email, and password are required. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); User result = await account.create( userId: '', email: 'email@example.com', password: '', name: '', // optional ); ``` -------------------------------- ### Create and Upload a File to Appwrite Storage Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/create-file.md Uploads a file to a specified bucket in Appwrite Storage. Ensure you have initialized the Appwrite client and Storage service. The `InputFile` requires a local file path and a desired filename. ```dart import 'dart:io'; import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Storage storage = Storage(client); File result = await storage.createFile( bucketId: '', fileId: '', file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), permissions: [Permission.read(Role.any())], // optional ); ``` -------------------------------- ### Initialize Appwrite Client Source: https://github.com/appwrite/sdk-for-flutter/blob/main/README.md Initialize the Appwrite client with your project ID. If using a self-hosted instance, also set the Appwrite endpoint. ```dart Client client = Client().setProject(''); ``` -------------------------------- ### Download File Preview Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/get-file-preview.md Use this snippet to download a file preview as bytes. You can then save these bytes to a file or process them further. All parameters are optional and can be used to customize the preview. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; import 'dart:io'; import 'dart:typed_data'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Storage storage = Storage(client); // Downloading file Future downloadFilePreview() async { try { Uint8List bytes = await storage.getFilePreview( bucketId: '', fileId: '', width: 0, // optional height: 0, // optional gravity: enums.ImageGravity.center, // optional quality: -1, // optional borderWidth: 0, // optional borderColor: '', // optional borderRadius: 0, // optional opacity: 0, // optional rotation: -360, // optional background: '', // optional output: enums.ImageFormat.jpg, // optional token: '', // optional ); final file = File('path_to_file/filename.ext'); await file.writeAsBytes(bytes); print('File preview downloaded successfully.'); } catch (e) { print('Error downloading file preview: $e'); } } ``` -------------------------------- ### List all currencies Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/locale/list-currencies.md Retrieves a list of all supported currencies. Ensure your client is initialized with the correct endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Locale locale = Locale(client); CurrencyList result = await locale.listCurrencies(); ``` -------------------------------- ### Get Function Execution Details in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/functions/get-execution.md Use this snippet to retrieve the details of a specific function execution by providing the function ID and execution ID. Ensure you have initialized the Appwrite client and Functions service beforehand. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Functions functions = Functions(client); Execution result = await functions.getExecution( functionId: '', executionId: '', ); ``` -------------------------------- ### Display Flag Image in Flutter Widget Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-flag.md This example shows how to use the avatars.getFlag method within a FutureBuilder to display a flag image directly in your Flutter application. This works for both public and private files, provided the user is logged in for private files. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; import 'package:flutter/material.dart'; // Assuming client and avatars are initialized as shown in the previous example // Client client = Client()...; // Avatars avatars = Avatars(client); // Displaying image preview FutureBuilder( future: avatars.getFlag( code: enums.Flag.afghanistan, width:0 , // optional height:0 , // optional quality:-1 , // optional ), // Works for both public file and private file, for private files you need to be logged in builder: (context, snapshot) { return snapshot.hasData && snapshot.data != null ? Image.memory(snapshot.data) : CircularProgressIndicator(); } ); ``` -------------------------------- ### Execute GraphQL Mutation Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/graphql/mutation.md Initializes the Appwrite client and executes a GraphQL mutation. Ensure you replace placeholders with your actual API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Graphql graphql = Graphql(client); Any result = await graphql.mutation( query: {}, ); ``` -------------------------------- ### Create a New User Account Source: https://github.com/appwrite/sdk-for-flutter/blob/main/README.md Make your first request to create a new user account using the Appwrite Account service. This requires a unique user ID, email, password, and name. ```dart Account account = Account(client); User user = await account.create( userId: ID.unique(), email: 'email@example.com', password: 'password', name: 'Walter O'Brien', ); ``` -------------------------------- ### List Sessions Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/list-sessions.md Retrieves a list of all active sessions for the current user. Ensure the client is initialized with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); SessionList result = await account.listSessions(); ``` -------------------------------- ### List Presences with Appwrite Flutter SDK Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/presences/list.md Use this snippet to fetch a list of presences. Ensure you have initialized the Appwrite client with your endpoint and project ID. The `list` method accepts optional queries, a boolean to include total count, and a TTL value. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Presences presences = Presences(client); PresenceList result = await presences.list( queries: [], // optional total: false, // optional ttl: 0, // optional ); ``` -------------------------------- ### Create Email/Password Session in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-email-password-session.md Use this snippet to create a new user session by providing their email and password. Ensure the client and account services are initialized with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Session result = await account.createEmailPasswordSession( email: 'email@example.com', password: 'password', ); ``` -------------------------------- ### Create a Transaction with TablesDB Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/create-transaction.md Initialize the Appwrite client and use the TablesDB service to create a new transaction. The transaction has an optional time-to-live (TTL) in seconds. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID TablesDB tablesDB = TablesDB(client); Transaction result = await tablesDB.createTransaction( ttl: 60, // optional ); ``` -------------------------------- ### Create Email Verification Token (Flutter) Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-email-verification.md Use this snippet to initiate the email verification process for a user. Ensure you have initialized the Appwrite client and Account object with your project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Token result = await account.createEmailVerification( url: 'https://example.com', ); ``` -------------------------------- ### Create Function Execution Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/functions/create-execution.md Initiates an execution for a specified Appwrite Function. Ensure you have initialized the Client and Functions services. The `xasync` parameter controls whether the execution runs asynchronously. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Functions functions = Functions(client); Execution result = await functions.createExecution( functionId: '', body: '', // optional xasync: false, // optional path: '', // optional method: enums.ExecutionMethod.gET, // optional headers: {}, scheduledAt: '', // optional ); ``` -------------------------------- ### List Transactions in Appwrite Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/list-transactions.md This snippet shows how to initialize the Appwrite client and list transactions. Ensure you replace '' and '' with your actual project details. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID TablesDB tablesDB = TablesDB(client); TransactionList result = await tablesDB.listTransactions( queries: [], // optional ); ``` -------------------------------- ### Create TOTP Authenticator Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-mfa-authenticator.md Initiates the creation of a TOTP authenticator for a user. This is the first step in setting up MFA for your users. Ensure your client is properly configured with your Appwrite endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); MfaType result = await account.createMFAAuthenticator( type: enums.AuthenticatorType.totp, ); ``` -------------------------------- ### Generate Initials Avatar and Save to File Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-initials.md This snippet demonstrates how to generate an avatar based on initials and save it as a file. Ensure you have initialized the Appwrite client and Avatars service. The parameters for `getInitials` are optional. ```dart import 'package:appwrite/appwrite.dart'; import 'dart:typed_data'; import 'dart:io'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Avatars avatars = Avatars(client); // Downloading file Future downloadInitialsAvatar() async { Uint8List bytes = await avatars.getInitials( name: '', // optional width: 0, // optional height: 0, // optional background: '' // optional ); final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes); } ``` -------------------------------- ### Create Operations in Appwrite Database Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/databases/create-operations.md This snippet demonstrates how to initiate a create operation within an Appwrite database using a transaction. Ensure you have initialized the Appwrite client, databases service, and have the necessary IDs. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Databases databases = Databases(client); Transaction result = await databases.createOperations( transactionId: '', operations: [ { "action": "create", "databaseId": "", "collectionId": "", "documentId": "", "data": { "name": "Walter O\'Brien" } } ], // optional ); ``` -------------------------------- ### Display Favicon in Image Preview Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-favicon.md This snippet shows how to fetch a favicon and display it directly within an Image widget using a FutureBuilder. This works for both public and private files, but requires user authentication for private files. ```dart import 'package:appwrite/appwrite.dart'; import 'package:flutter/material.dart'; // Assume client and avatars are initialized as shown in the previous example // Client client = Client()...; // Avatars avatars = Avatars(client); // Example usage within a Flutter widget Widget faviconPreview() { return FutureBuilder( future: avatars.getFavicon( url:'https://example.com' ), // Works for both public file and private file, for private files you need to be logged in builder: (context, snapshot) { return snapshot.hasData && snapshot.data != null ? Image.memory(snapshot.data as Uint8List) : CircularProgressIndicator(); } ); } ``` -------------------------------- ### List MFA Factors in Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/list-mfa-factors.md Initializes the Appwrite client and account service to retrieve a list of MFA factors for the authenticated user. Ensure you have set your API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); MfaFactors result = await account.listMFAFactors(); ``` -------------------------------- ### Create Verification Token Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-verification.md Initiates the account verification process by creating a verification token. This token is usually sent to the user's email address to confirm their identity. Ensure you have initialized the Appwrite client and Account service before calling this method. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Token result = await account.createVerification( url: 'https://example.com', ); ``` -------------------------------- ### Update Account Status Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/update-status.md Initializes the Appwrite client and account, then calls the updateStatus method. Ensure you replace placeholders with your actual API endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); User result = await account.updateStatus(); ``` -------------------------------- ### Download Avatar Image Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-image.md Fetches an image from a given URL and saves it to a local file. Ensure the Appwrite client is initialized with your endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; import 'dart:typed_data'; import 'dart:io'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Avatars avatars = Avatars(client); // Downloading file Future downloadImage() async { Uint8List bytes = await avatars.getImage( url: 'https://example.com', width: 0, // optional height: 0, // optional ); final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes); } ``` -------------------------------- ### Download Favicon as Bytes Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-favicon.md Use this snippet to download a favicon for a given URL. The result is returned as a Uint8List, which can be saved to a file or used directly. ```dart import 'package:appwrite/appwrite.dart'; import 'dart:typed_data'; import 'dart:io'; // Initialize Appwrite client Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Avatars avatars = Avatars(client); // Downloading file Future downloadFavicon() async { try { Uint8List bytes = await avatars.getFavicon( url: 'https://example.com', ); // Save the downloaded bytes to a file final file = File('path_to_file/filename.ext'); await file.writeAsBytes(bytes); print('Favicon downloaded successfully.'); } catch (e) { print('Error downloading favicon: $e'); } } ``` -------------------------------- ### Update MFA Challenge with OTP Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/update-mfa-challenge.md Use this method to verify the MFA challenge by providing the challenge ID and the One-Time Password (OTP). Ensure you have initialized the Appwrite client and Account object. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); Session result = await account.updateMFAChallenge( challengeId: '', otp: '', ); ``` -------------------------------- ### Create Email MFA Challenge Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/account/create-mfa-challenge.md Initiates an MFA challenge for email verification. Ensure your Appwrite client is configured with the correct endpoint and project ID. ```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Account account = Account(client); MfaChallenge result = await account.createMFAChallenge( factor: enums.AuthenticationFactor.email, ); ``` -------------------------------- ### Create a Messaging Subscriber Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/messaging/create-subscriber.md Use this snippet to create a new subscriber for a specific topic. Ensure your client is initialized with your project details and API endpoint. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Messaging messaging = Messaging(client); Subscriber result = await messaging.createSubscriber( topicId: '', subscriberId: '', targetId: '', ); ``` -------------------------------- ### Display Image Preview Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/storage/get-file-download.md Use `getFileDownload` within a `FutureBuilder` to display an image preview directly in your Flutter UI. This method works for both public and private files, but requires the user to be logged in for private files. The optional `token` parameter is required for private files. ```dart import 'package:appwrite/appwrite.dart'; import 'package:flutter/material.dart'; // Assuming client and storage are already initialized as shown in the previous example // Client client = Client()...; // Storage storage = Storage(client); // Displaying image preview Widget getImagePreview(String bucketId, String fileId, String token) { return FutureBuilder< Uint8List>( // Specify the type of data the Future will return future: storage.getFileDownload( bucketId: bucketId, fileId: fileId, token: token, // optional ), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // Show loading indicator while fetching } else if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); // Show error message if something goes wrong } else if (snapshot.hasData && snapshot.data != null) { return Image.memory(snapshot.data!); // Display the image if data is available } else { return Text('No image available'); // Placeholder if no data } } ); } ``` -------------------------------- ### Generate and Save QR Code Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/avatars/get-qr.md Generates a QR code for the given text and saves it as a file. Ensure you have initialized the Appwrite client and Avatars service. ```dart import 'package:appwrite/appwrite.dart'; import 'dart:io'; import 'dart:typed_data'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Avatars avatars = Avatars(client); // Downloading file Future generateAndSaveQr() async { Uint8List bytes = await avatars.getQR( text: '', size: 1, // optional margin: 0, // optional download: false, // optional ); final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes); } ``` -------------------------------- ### Create Team - Flutter Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/teams/create.md Use the `teams.create` method to create a new team. Ensure your client is initialized with your project's endpoint and ID. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID Teams teams = Teams(client); Team result = await teams.create( teamId: '', name: '', roles: [], // optional ); ``` -------------------------------- ### List Rows from a Table Source: https://github.com/appwrite/sdk-for-flutter/blob/main/docs/examples/tablesdb/list-rows.md Use the `listRows` method to fetch rows from a table. Ensure your client is initialized with your project details and endpoint. Optional parameters like `queries`, `transactionId`, `total`, and `ttl` can be provided for advanced use cases. ```dart import 'package:appwrite/appwrite.dart'; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID TablesDB tablesDB = TablesDB(client); RowList result = await tablesDB.listRows( databaseId: '', tableId: '', queries: [], // optional transactionId: '', // optional total: false, // optional ttl: 0, // optional ); ```