Skip to content

Commit e5d0f3a

Browse files
committed
Null-safety support
1 parent e714f9a commit e5d0f3a

11 files changed

+122
-85
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.0-dev.1
2+
3+
- Upgraded to Null-safety, minimum Dart SDK required 2.12.0
4+
- Upgraded all underlying dependencies to null safe version
5+
16
## 0.3.1
27

38
- Minor fixes for custom exceptions

README.md

+41-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Appwrite Dart SDK
22

3-
[![pub package](https://img.shields.io/pub/v/dart_appwrite.svg)](https://pub.dartlang.org/packages/dart_appwrite)
4-
![License](https://img.shields.io/github/license/appwrite/sdk-for-dart.svg?v=1)
5-
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?v=1)
3+
[![pub package](https://img.shields.io/pub/v/dart_appwrite.svg?style=flat-square)](https://pub.dartlang.org/packages/dart_appwrite)
4+
![License](https://img.shields.io/github/license/appwrite/sdk-for-dart.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?style=flat-square)
6+
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
7+
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
68

7-
**This SDK is compatible with Appwrite server version 0.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-dart/releases).**
9+
**This SDK is compatible with Appwrite server version 0.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-dart/releases).**
810

9-
> This is the Dart SDK for integrating with Appwrite from your Dart server-side code.
10-
If you're looking for the Flutter SDK you should check [appwrite/sdk-for-flutter](https://github.com/appwrite/sdk-for-flutter)
11+
> This is the Dart SDK for integrating with Appwrite from your Dart server-side code. If you're looking for the Flutter SDK you should check [appwrite/sdk-for-flutter](https://github.com/appwrite/sdk-for-flutter)
1112
1213
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.
1314
Use the Dart SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools.
@@ -23,7 +24,7 @@ Add this to your package's `pubspec.yaml` file:
2324

2425
```yml
2526
dependencies:
26-
dart_appwrite: ^0.4.0
27+
dart_appwrite: ^0.5.0-dev.1
2728
```
2829
2930
You can install packages from the command line:
@@ -33,6 +34,39 @@ pub get dart_appwrite
3334
```
3435

3536

37+
## Getting Started
38+
39+
### Initialize & Make API Request
40+
Once you add the dependencies, its extremely easy to get started with the SDK; All you need to do is import the package in your code, set your Appwrite credentials, and start making API calls. Below is a simple example:
41+
42+
```dart
43+
import 'package:dart_appwrite/dart_appwrite.dart';
44+
45+
void main() async {
46+
Client client = Client();
47+
.setEndpoint('http://[HOSTNAME_OR_IP]/v1') // Make sure your endpoint is accessible
48+
.setProject('5ff3379a01d25') // Your project ID
49+
.setKey('cd868c7af8bdc893b4...93b7535db89')
50+
51+
Users users = Users(client);
52+
53+
try {
54+
final response = await users.create(email: ‘[email protected]’,password: ‘password’, name: ‘name’);
55+
print(response.data);
56+
} on AppwriteException catch(e) {
57+
print(e.message);
58+
}
59+
}
60+
```
61+
62+
### Learn more
63+
You can use followng resources to learn more and get help
64+
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
65+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
66+
- 💬 [Discord Community](https://appwrite.io/discord)
67+
- 🚂 [Appwrite Dart Playground](https://github.com/appwrite/playground-for-dart)
68+
69+
3670
## Contribution
3771

3872
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

lib/client.dart

+18-20
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ part of dart_appwrite;
33
class Client {
44
String endPoint;
55
String type = 'unknown';
6-
Map<String, String> headers;
7-
Map<String, String> config;
6+
Map<String, String>? headers;
7+
late Map<String, String> config;
88
bool selfSigned;
99
bool initialized = false;
1010
Dio http;
1111

12-
Client({this.endPoint = 'https://appwrite.io/v1', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
12+
Client({this.endPoint = 'https://appwrite.io/v1', this.selfSigned = false, Dio? http}) : this.http = http ?? Dio() {
1313

1414
this.headers = {
1515
'content-type': 'application/json',
16-
'x-sdk-version': 'appwrite:dart:0.4.0',
16+
'x-sdk-version': 'appwrite:dart:0.5.0-dev.1',
1717
};
1818

1919
this.config = {};
2020

2121
assert(endPoint.startsWith(RegExp("http://|https://")), "endPoint $endPoint must start with 'http'");
22+
init();
2223
}
2324

2425

@@ -54,19 +55,17 @@ class Client {
5455
}
5556

5657
Client addHeader(String key, String value) {
57-
headers[key] = value;
58+
headers![key] = value;
5859

5960
return this;
6061
}
6162

62-
Future init() async {
63-
if(!initialized) {
63+
void init() {
6464
this.http.options.baseUrl = this.endPoint;
65-
this.http.options.validateStatus = (status) => status < 400;
66-
}
65+
this.http.options.validateStatus = (status) => status! < 400;
6766
}
6867

69-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) async {
68+
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType? responseType}) async {
7069
if(selfSigned) {
7170
// Allow self signed requests
7271
(http.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
@@ -75,18 +74,17 @@ class Client {
7574
};
7675
}
7776

78-
await this.init();
79-
8077
// Origin is hardcoded for testing
8178
Options options = Options(
82-
headers: {...this.headers, ...headers},
79+
headers: {...this.headers!, ...headers},
8380
method: method.name(),
84-
responseType: responseType
81+
responseType: responseType,
82+
listFormat: ListFormat.multiCompatible,
8583
);
8684
try {
8785

8886
if(headers['content-type'] == 'multipart/form-data') {
89-
return await http.request(path, data: FormData.fromMap(params), options: options);
87+
return await http.request(path, data: FormData.fromMap(params,ListFormat.multiCompatible), options: options);
9088
}
9189

9290
if (method == HttpMethod.get) {
@@ -103,16 +101,16 @@ class Client {
103101
throw AppwriteException(e.message);
104102
}
105103
if(responseType == ResponseType.bytes) {
106-
if(e.response.headers['content-type'].contains('application/json')) {
107-
final res = json.decode(utf8.decode(e.response.data));
108-
throw AppwriteException(res['message'],res['code'], e.response);
104+
if(e.response!.headers['content-type']?.contains('application/json') ?? false) {
105+
final res = json.decode(utf8.decode(e.response!.data));
106+
throw AppwriteException(res['message'],res['code'], res);
109107
} else {
110108
throw AppwriteException(e.message);
111109
}
112110
}
113-
throw AppwriteException(e.response.data['message'],e.response.data['code'], e.response.data);
111+
throw AppwriteException(e.response?.data['message'],e.response?.data['code'], e.response?.data);
114112
} catch(e) {
115-
throw AppwriteException(e.message);
113+
throw AppwriteException(e.toString());
116114
}
117115
}
118116
}

lib/exception.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of dart_appwrite;
22

33
class AppwriteException implements Exception {
4-
final String message;
5-
final int code;
4+
final String? message;
5+
final int? code;
66
final dynamic response;
77

88
AppwriteException([this.message = "", this.code, this.response]);

lib/services/avatars.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Avatars extends Service {
1111
/// /account/sessions endpoint. Use width, height and quality arguments to
1212
/// change the output settings.
1313
///
14-
Future<Response> getBrowser({@required String code, int width = 100, int height = 100, int quality = 100}) {
14+
Future<Response> getBrowser({required String code, int width = 100, int height = 100, int quality = 100}) {
1515
final String path = '/avatars/browsers/{code}'.replaceAll(RegExp('{code}'), code);
1616

1717
final Map<String, dynamic> params = {
@@ -35,7 +35,7 @@ class Avatars extends Service {
3535
/// provider you need. Use width, height and quality arguments to change the
3636
/// output settings.
3737
///
38-
Future<Response> getCreditCard({@required String code, int width = 100, int height = 100, int quality = 100}) {
38+
Future<Response> getCreditCard({required String code, int width = 100, int height = 100, int quality = 100}) {
3939
final String path = '/avatars/credit-cards/{code}'.replaceAll(RegExp('{code}'), code);
4040

4141
final Map<String, dynamic> params = {
@@ -59,7 +59,7 @@ class Avatars extends Service {
5959
/// website URL.
6060
///
6161
///
62-
Future<Response> getFavicon({@required String url}) {
62+
Future<Response> getFavicon({required String url}) {
6363
final String path = '/avatars/favicon';
6464

6565
final Map<String, dynamic> params = {
@@ -81,7 +81,7 @@ class Avatars extends Service {
8181
/// users. The code argument receives the 2 letter country code. Use width,
8282
/// height and quality arguments to change the output settings.
8383
///
84-
Future<Response> getFlag({@required String code, int width = 100, int height = 100, int quality = 100}) {
84+
Future<Response> getFlag({required String code, int width = 100, int height = 100, int quality = 100}) {
8585
final String path = '/avatars/flags/{code}'.replaceAll(RegExp('{code}'), code);
8686

8787
final Map<String, dynamic> params = {
@@ -106,7 +106,7 @@ class Avatars extends Service {
106106
/// remote images in your app or in case you want to make sure a 3rd party
107107
/// image is properly served using a TLS protocol.
108108
///
109-
Future<Response> getImage({@required String url, int width = 400, int height = 400}) {
109+
Future<Response> getImage({required String url, int width = 400, int height = 400}) {
110110
final String path = '/avatars/image';
111111

112112
final Map<String, dynamic> params = {
@@ -162,7 +162,7 @@ class Avatars extends Service {
162162
/// Converts a given plain text to a QR code image. You can use the query
163163
/// parameters to change the size and style of the resulting image.
164164
///
165-
Future<Response> getQR({@required String text, int size = 400, int margin = 1, bool download = false}) {
165+
Future<Response> getQR({required String text, int size = 400, int margin = 1, bool download = false}) {
166166
final String path = '/avatars/qr';
167167

168168
final Map<String, dynamic> params = {

lib/services/database.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Database extends Service {
3232
///
3333
/// Create a new Collection.
3434
///
35-
Future<Response> createCollection({@required String name, @required List read, @required List write, @required List rules}) {
35+
Future<Response> createCollection({required String name, required List read, required List write, required List rules}) {
3636
final String path = '/database/collections';
3737

3838
final Map<String, dynamic> params = {
@@ -54,7 +54,7 @@ class Database extends Service {
5454
/// Get a collection by its unique ID. This endpoint response returns a JSON
5555
/// object with the collection metadata.
5656
///
57-
Future<Response> getCollection({@required String collectionId}) {
57+
Future<Response> getCollection({required String collectionId}) {
5858
final String path = '/database/collections/{collectionId}'.replaceAll(RegExp('{collectionId}'), collectionId);
5959

6060
final Map<String, dynamic> params = {
@@ -71,7 +71,7 @@ class Database extends Service {
7171
///
7272
/// Update a collection by its unique ID.
7373
///
74-
Future<Response> updateCollection({@required String collectionId, @required String name, @required List read, @required List write, List rules = const []}) {
74+
Future<Response> updateCollection({required String collectionId, required String name, required List read, required List write, List rules = const []}) {
7575
final String path = '/database/collections/{collectionId}'.replaceAll(RegExp('{collectionId}'), collectionId);
7676

7777
final Map<String, dynamic> params = {
@@ -93,7 +93,7 @@ class Database extends Service {
9393
/// Delete a collection by its unique ID. Only users with write permissions
9494
/// have access to delete this resource.
9595
///
96-
Future<Response> deleteCollection({@required String collectionId}) {
96+
Future<Response> deleteCollection({required String collectionId}) {
9797
final String path = '/database/collections/{collectionId}'.replaceAll(RegExp('{collectionId}'), collectionId);
9898

9999
final Map<String, dynamic> params = {
@@ -113,7 +113,7 @@ class Database extends Service {
113113
/// of the project's documents. [Learn more about different API
114114
/// modes](/docs/admin).
115115
///
116-
Future<Response> listDocuments({@required String collectionId, List filters = const [], int limit = 25, int offset = 0, String orderField = '', OrderType orderType = OrderType.asc, String orderCast = 'string', String search = ''}) {
116+
Future<Response> listDocuments({required String collectionId, List filters = const [], int limit = 25, int offset = 0, String orderField = '', OrderType orderType = OrderType.asc, String orderCast = 'string', String search = ''}) {
117117
final String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
118118

119119
final Map<String, dynamic> params = {
@@ -140,7 +140,7 @@ class Database extends Service {
140140
/// integration](/docs/server/database#databaseCreateCollection) API or
141141
/// directly from your database console.
142142
///
143-
Future<Response> createDocument({@required String collectionId, @required Map data, @required List read, @required List write, String parentDocument = '', String parentProperty = '', String parentPropertyType = 'assign'}) {
143+
Future<Response> createDocument({required String collectionId, required Map data, required List read, required List write, String parentDocument = '', String parentProperty = '', String parentPropertyType = 'assign'}) {
144144
final String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
145145

146146
final Map<String, dynamic> params = {
@@ -164,7 +164,7 @@ class Database extends Service {
164164
/// Get a document by its unique ID. This endpoint response returns a JSON
165165
/// object with the document data.
166166
///
167-
Future<Response> getDocument({@required String collectionId, @required String documentId}) {
167+
Future<Response> getDocument({required String collectionId, required String documentId}) {
168168
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
169169

170170
final Map<String, dynamic> params = {
@@ -182,7 +182,7 @@ class Database extends Service {
182182
/// Update a document by its unique ID. Using the patch method you can pass
183183
/// only specific fields that will get updated.
184184
///
185-
Future<Response> updateDocument({@required String collectionId, @required String documentId, @required Map data, @required List read, @required List write}) {
185+
Future<Response> updateDocument({required String collectionId, required String documentId, required Map data, required List read, required List write}) {
186186
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
187187

188188
final Map<String, dynamic> params = {
@@ -204,7 +204,7 @@ class Database extends Service {
204204
/// documents, its attributes and relations to other documents. Child documents
205205
/// **will not** be deleted.
206206
///
207-
Future<Response> deleteDocument({@required String collectionId, @required String documentId}) {
207+
Future<Response> deleteDocument({required String collectionId, required String documentId}) {
208208
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
209209

210210
final Map<String, dynamic> params = {

0 commit comments

Comments
 (0)