Skip to content

Commit 44718a4

Browse files
committed
prerelease of v0.3
1 parent ae088ae commit 44718a4

File tree

6 files changed

+76
-38
lines changed

6 files changed

+76
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.0
2+
3+
- Updated package dependencies (@lohanidamodar)
4+
- Added Flutter for Web compatibility (@lohanidamodar)
5+
16
## 0.2.3
27

38
- Fixed OAuth2 cookie bug, where a new session cookie couldn't overwrite an old cookie

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add this to your package's `pubspec.yaml` file:
2020

2121
```yml
2222
dependencies:
23-
appwrite: ^0.2.3
23+
appwrite: ^0.3.0-dev.1
2424
```
2525
2626
You can install packages from the command line:

lib/client.dart

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22

33
import 'package:dio/dio.dart';
4+
import 'package:flutter/foundation.dart';
45
import 'package:dio/adapter.dart';
56
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
67
import 'package:cookie_jar/cookie_jar.dart';
@@ -20,17 +21,21 @@ class Client {
2021
PersistCookieJar cookieJar;
2122

2223
Client({this.endPoint = 'https://appwrite.io/v1', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
23-
24-
type = (Platform.isIOS) ? 'ios' : type;
25-
type = (Platform.isMacOS) ? 'macos' : type;
26-
type = (Platform.isAndroid) ? 'android' : type;
27-
type = (Platform.isLinux) ? 'linux' : type;
28-
type = (Platform.isWindows) ? 'windows' : type;
29-
type = (Platform.isFuchsia) ? 'fuchsia' : type;
24+
// Platform is not supported in web so if web, set type to web automatically and skip Platform check
25+
if(kIsWeb) {
26+
type = 'web';
27+
}else{
28+
type = (Platform.isIOS) ? 'ios' : type;
29+
type = (Platform.isMacOS) ? 'macos' : type;
30+
type = (Platform.isAndroid) ? 'android' : type;
31+
type = (Platform.isLinux) ? 'linux' : type;
32+
type = (Platform.isWindows) ? 'windows' : type;
33+
type = (Platform.isFuchsia) ? 'fuchsia' : type;
34+
}
3035

3136
this.headers = {
3237
'content-type': 'application/json',
33-
'x-sdk-version': 'appwrite:dart:0.2.3',
38+
'x-sdk-version': 'appwrite:flutter:0.3.0-dev.1',
3439
};
3540

3641
this.config = {};
@@ -78,17 +83,20 @@ class Client {
7883

7984
Future init() async {
8085
if(!initialized) {
81-
final Directory cookieDir = await _getCookiePath();
82-
83-
cookieJar = new PersistCookieJar(dir:cookieDir.path);
86+
// if web skip cookie implementation and origin header as those are automatically handled by browsers
87+
if(!kIsWeb) {
88+
final Directory cookieDir = await _getCookiePath();
89+
cookieJar = new PersistCookieJar(dir:cookieDir.path);
90+
this.http.interceptors.add(CookieManager(cookieJar));
91+
PackageInfo packageInfo = await PackageInfo.fromPlatform();
92+
addHeader('Origin', 'appwrite-' + type + '://' + packageInfo.packageName);
93+
}else{
94+
// if web set httpClientAdapter as BrowserHttpClientAdapter with withCredentials true to make cookies work
95+
this.http.options.extra['withCredentials'] = true;
96+
}
8497

8598
this.http.options.baseUrl = this.endPoint;
8699
this.http.options.validateStatus = (status) => status < 400;
87-
this.http.interceptors.add(CookieManager(cookieJar));
88-
89-
PackageInfo packageInfo = await PackageInfo.fromPlatform();
90-
91-
addHeader('Origin', 'appwrite-' + type + '://' + packageInfo.packageName);
92100
}
93101
}
94102

@@ -114,6 +122,10 @@ class Client {
114122
}
115123

116124
if (method == HttpMethod.get) {
125+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
126+
params[key] = params[key].toString();
127+
}});
128+
117129
return http.get(path, queryParameters: params, options: options);
118130
} else {
119131
return http.request(path, data: params, options: options);

lib/services/avatars.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class Avatars extends Service {
2727
'project': client.config['project'],
2828
};
2929

30+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
31+
params[key] = params[key].toString();
32+
}});
33+
3034
Uri endpoint = Uri.parse(client.endPoint);
3135
Uri location = new Uri(scheme: endpoint.scheme,
3236
host: endpoint.host,
@@ -55,6 +59,10 @@ class Avatars extends Service {
5559
'project': client.config['project'],
5660
};
5761

62+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
63+
params[key] = params[key].toString();
64+
}});
65+
5866
Uri endpoint = Uri.parse(client.endPoint);
5967
Uri location = new Uri(scheme: endpoint.scheme,
6068
host: endpoint.host,
@@ -79,6 +87,10 @@ class Avatars extends Service {
7987
'project': client.config['project'],
8088
};
8189

90+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
91+
params[key] = params[key].toString();
92+
}});
93+
8294
Uri endpoint = Uri.parse(client.endPoint);
8395
Uri location = new Uri(scheme: endpoint.scheme,
8496
host: endpoint.host,
@@ -106,6 +118,10 @@ class Avatars extends Service {
106118
'project': client.config['project'],
107119
};
108120

121+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
122+
params[key] = params[key].toString();
123+
}});
124+
109125
Uri endpoint = Uri.parse(client.endPoint);
110126
Uri location = new Uri(scheme: endpoint.scheme,
111127
host: endpoint.host,
@@ -134,6 +150,10 @@ class Avatars extends Service {
134150
'project': client.config['project'],
135151
};
136152

153+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
154+
params[key] = params[key].toString();
155+
}});
156+
137157
Uri endpoint = Uri.parse(client.endPoint);
138158
Uri location = new Uri(scheme: endpoint.scheme,
139159
host: endpoint.host,
@@ -161,6 +181,10 @@ class Avatars extends Service {
161181
'project': client.config['project'],
162182
};
163183

184+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
185+
params[key] = params[key].toString();
186+
}});
187+
164188
Uri endpoint = Uri.parse(client.endPoint);
165189
Uri location = new Uri(scheme: endpoint.scheme,
166190
host: endpoint.host,

lib/services/storage.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class Storage extends Service {
124124
'project': client.config['project'],
125125
};
126126

127+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
128+
params[key] = params[key].toString();
129+
}});
130+
127131
Uri endpoint = Uri.parse(client.endPoint);
128132
Uri location = new Uri(scheme: endpoint.scheme,
129133
host: endpoint.host,
@@ -154,6 +158,10 @@ class Storage extends Service {
154158
'project': client.config['project'],
155159
};
156160

161+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
162+
params[key] = params[key].toString();
163+
}});
164+
157165
Uri endpoint = Uri.parse(client.endPoint);
158166
Uri location = new Uri(scheme: endpoint.scheme,
159167
host: endpoint.host,
@@ -178,6 +186,10 @@ class Storage extends Service {
178186
'project': client.config['project'],
179187
};
180188

189+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
190+
params[key] = params[key].toString();
191+
}});
192+
181193
Uri endpoint = Uri.parse(client.endPoint);
182194
Uri location = new Uri(scheme: endpoint.scheme,
183195
host: endpoint.host,

pubspec.yaml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: appwrite
2-
version: 0.2.3
2+
version: 0.3.0-dev.1
33
description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
44
homepage: https://appwrite.io
55
repository: https://github.com/appwrite/sdk-for-flutter
@@ -9,30 +9,15 @@ environment:
99
sdk: '>=2.6.0 <3.0.0'
1010
dependencies:
1111
meta: ^1.1.8
12-
path_provider: ^1.6.5
13-
package_info: ^0.4.0+16
14-
dio: ^3.0.0
15-
cookie_jar: ^1.0.0
12+
path_provider: ^1.6.14
13+
package_info: ^0.4.3
14+
dio: ^3.0.10
15+
cookie_jar: ^1.0.1
1616
dio_cookie_manager: ^1.0.0
1717
flutter_web_auth: ^0.2.4
1818
flutter:
1919
sdk: flutter
2020

21-
# The following adds the Cupertino Icons font to your application.
22-
# Use with the CupertinoIcons class for iOS style icons.
23-
cupertino_icons: ^0.1.2
24-
2521
dev_dependencies:
2622
flutter_test:
27-
sdk: flutter
28-
29-
# For information on the generic Dart part of this file, see the
30-
# following page: https://dart.dev/tools/pub/pubspec
31-
32-
# The following section is specific to Flutter.
33-
flutter:
34-
35-
# The following line ensures that the Material Icons font is
36-
# included with your application, so that you can use the icons in
37-
# the material Icons class.
38-
uses-material-design: true
23+
sdk: flutter

0 commit comments

Comments
 (0)