Skip to content

Commit 34cfa41

Browse files
authored
Merge pull request #284 from appwrite/dev
feat: Flutter SDK update for version 20.3.1
2 parents bfb1a4f + fd70624 commit 34cfa41

File tree

19 files changed

+751
-141
lines changed

19 files changed

+751
-141
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 20.3.1
4+
5+
* Fix passing of `null` values and stripping only non-nullable optional parameters from the request body
6+
37
## 20.3.0
48

59
* Add `total` parameter to list queries allowing skipping counting rows in a table for improved performance

README.md

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

2222
```yml
2323
dependencies:
24-
appwrite: ^20.3.0
24+
appwrite: ^20.3.1
2525
```
2626
2727
You can install packages from the command line:
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import 'package:appwrite/appwrite.dart';
2+
3+
Client client = Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
Avatars avatars = Avatars(client);
8+
9+
// Downloading file
10+
UInt8List bytes = await avatars.getScreenshot(
11+
url: 'https://example.com',
12+
headers: {}, // optional
13+
viewportWidth: 1, // optional
14+
viewportHeight: 1, // optional
15+
scale: 0.1, // optional
16+
theme: .light, // optional
17+
userAgent: '<USER_AGENT>', // optional
18+
fullpage: false, // optional
19+
locale: '<LOCALE>', // optional
20+
timezone: .africaAbidjan, // optional
21+
latitude: -90, // optional
22+
longitude: -180, // optional
23+
accuracy: 0, // optional
24+
touch: false, // optional
25+
permissions: [], // optional
26+
sleep: 0, // optional
27+
width: 0, // optional
28+
height: 0, // optional
29+
quality: -1, // optional
30+
output: .jpg, // optional
31+
)
32+
33+
final file = File('path_to_file/filename.ext');
34+
file.writeAsBytesSync(bytes);
35+
36+
// Displaying image preview
37+
FutureBuilder(
38+
future: avatars.getScreenshot(
39+
url:'https://example.com' ,
40+
headers:{} , // optional
41+
viewportWidth:1 , // optional
42+
viewportHeight:1 , // optional
43+
scale:0.1 , // optional
44+
theme: .light, // optional
45+
userAgent:'<USER_AGENT>' , // optional
46+
fullpage:false , // optional
47+
locale:'<LOCALE>' , // optional
48+
timezone: .africaAbidjan, // optional
49+
latitude:-90 , // optional
50+
longitude:-180 , // optional
51+
accuracy:0 , // optional
52+
touch:false , // optional
53+
permissions:[] , // optional
54+
sleep:0 , // optional
55+
width:0 , // optional
56+
height:0 , // optional
57+
quality:-1 , // optional
58+
output: .jpg, // optional
59+
), // Works for both public file and private file, for private files you need to be logged in
60+
builder: (context, snapshot) {
61+
return snapshot.hasData && snapshot.data != null
62+
? Image.memory(snapshot.data)
63+
: CircularProgressIndicator();
64+
}
65+
);

lib/enums.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ part 'src/enums/o_auth_provider.dart';
77
part 'src/enums/browser.dart';
88
part 'src/enums/credit_card.dart';
99
part 'src/enums/flag.dart';
10+
part 'src/enums/theme.dart';
11+
part 'src/enums/timezone.dart';
12+
part 'src/enums/output.dart';
1013
part 'src/enums/execution_method.dart';
1114
part 'src/enums/image_gravity.dart';
1215
part 'src/enums/image_format.dart';

lib/services/account.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Account extends Service {
3737
'userId': userId,
3838
'email': email,
3939
'password': password,
40-
'name': name,
40+
if (name != null) 'name': name,
4141
};
4242

4343
final Map<String, String> apiHeaders = {
@@ -83,8 +83,8 @@ class Account extends Service {
8383
const String apiPath = '/account/identities';
8484

8585
final Map<String, dynamic> apiParams = {
86-
'queries': queries,
87-
'total': total,
86+
if (queries != null) 'queries': queries,
87+
if (total != null) 'total': total,
8888
};
8989

9090
final Map<String, String> apiHeaders = {};
@@ -138,8 +138,8 @@ class Account extends Service {
138138
const String apiPath = '/account/logs';
139139

140140
final Map<String, dynamic> apiParams = {
141-
'queries': queries,
142-
'total': total,
141+
if (queries != null) 'queries': queries,
142+
if (total != null) 'total': total,
143143
};
144144

145145
final Map<String, String> apiHeaders = {};
@@ -563,7 +563,7 @@ class Account extends Service {
563563

564564
final Map<String, dynamic> apiParams = {
565565
'password': password,
566-
'oldPassword': oldPassword,
566+
if (oldPassword != null) 'oldPassword': oldPassword,
567567
};
568568

569569
final Map<String, String> apiHeaders = {
@@ -821,9 +821,9 @@ class Account extends Service {
821821
.replaceAll('{provider}', provider.value);
822822

823823
final Map<String, dynamic> params = {
824-
'success': success,
825-
'failure': failure,
826-
'scopes': scopes,
824+
if (success != null) 'success': success,
825+
if (failure != null) 'failure': failure,
826+
if (scopes != null) 'scopes': scopes,
827827
'project': client.config['project'],
828828
};
829829

@@ -985,7 +985,7 @@ class Account extends Service {
985985
final Map<String, dynamic> apiParams = {
986986
'targetId': targetId,
987987
'identifier': identifier,
988-
'providerId': providerId,
988+
if (providerId != null) 'providerId': providerId,
989989
};
990990

991991
final Map<String, String> apiHeaders = {
@@ -1062,7 +1062,7 @@ class Account extends Service {
10621062
final Map<String, dynamic> apiParams = {
10631063
'userId': userId,
10641064
'email': email,
1065-
'phrase': phrase,
1065+
if (phrase != null) 'phrase': phrase,
10661066
};
10671067

10681068
final Map<String, String> apiHeaders = {
@@ -1099,8 +1099,8 @@ class Account extends Service {
10991099
final Map<String, dynamic> apiParams = {
11001100
'userId': userId,
11011101
'email': email,
1102-
'url': url,
1103-
'phrase': phrase,
1102+
if (url != null) 'url': url,
1103+
if (phrase != null) 'phrase': phrase,
11041104
};
11051105

11061106
final Map<String, String> apiHeaders = {
@@ -1136,9 +1136,9 @@ class Account extends Service {
11361136
.replaceAll('{provider}', provider.value);
11371137

11381138
final Map<String, dynamic> params = {
1139-
'success': success,
1140-
'failure': failure,
1141-
'scopes': scopes,
1139+
if (success != null) 'success': success,
1140+
if (failure != null) 'failure': failure,
1141+
if (scopes != null) 'scopes': scopes,
11421142
'project': client.config['project'],
11431143
};
11441144

lib/services/avatars.dart

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Avatars extends Service {
2525
'/avatars/browsers/{code}'.replaceAll('{code}', code.value);
2626

2727
final Map<String, dynamic> params = {
28-
'width': width,
29-
'height': height,
30-
'quality': quality,
28+
if (width != null) 'width': width,
29+
if (height != null) 'height': height,
30+
if (quality != null) 'quality': quality,
3131
'project': client.config['project'],
3232
};
3333

@@ -54,9 +54,9 @@ class Avatars extends Service {
5454
'/avatars/credit-cards/{code}'.replaceAll('{code}', code.value);
5555

5656
final Map<String, dynamic> params = {
57-
'width': width,
58-
'height': height,
59-
'quality': quality,
57+
if (width != null) 'width': width,
58+
if (height != null) 'height': height,
59+
if (quality != null) 'quality': quality,
6060
'project': client.config['project'],
6161
};
6262

@@ -98,9 +98,9 @@ class Avatars extends Service {
9898
'/avatars/flags/{code}'.replaceAll('{code}', code.value);
9999

100100
final Map<String, dynamic> params = {
101-
'width': width,
102-
'height': height,
103-
'quality': quality,
101+
if (width != null) 'width': width,
102+
if (height != null) 'height': height,
103+
if (quality != null) 'quality': quality,
104104
'project': client.config['project'],
105105
};
106106

@@ -126,8 +126,8 @@ class Avatars extends Service {
126126

127127
final Map<String, dynamic> params = {
128128
'url': url,
129-
'width': width,
130-
'height': height,
129+
if (width != null) 'width': width,
130+
if (height != null) 'height': height,
131131
'project': client.config['project'],
132132
};
133133

@@ -157,10 +157,10 @@ class Avatars extends Service {
157157
const String apiPath = '/avatars/initials';
158158

159159
final Map<String, dynamic> params = {
160-
'name': name,
161-
'width': width,
162-
'height': height,
163-
'background': background,
160+
if (name != null) 'name': name,
161+
if (width != null) 'width': width,
162+
if (height != null) 'height': height,
163+
if (background != null) 'background': background,
164164
'project': client.config['project'],
165165
};
166166

@@ -178,9 +178,71 @@ class Avatars extends Service {
178178

179179
final Map<String, dynamic> params = {
180180
'text': text,
181-
'size': size,
182-
'margin': margin,
183-
'download': download,
181+
if (size != null) 'size': size,
182+
if (margin != null) 'margin': margin,
183+
if (download != null) 'download': download,
184+
'project': client.config['project'],
185+
};
186+
187+
final res = await client.call(HttpMethod.get,
188+
path: apiPath, params: params, responseType: ResponseType.bytes);
189+
return res.data;
190+
}
191+
192+
/// Use this endpoint to capture a screenshot of any website URL. This endpoint
193+
/// uses a headless browser to render the webpage and capture it as an image.
194+
///
195+
/// You can configure the browser viewport size, theme, user agent,
196+
/// geolocation, permissions, and more. Capture either just the viewport or the
197+
/// full page scroll.
198+
///
199+
/// When width and height are specified, the image is resized accordingly. If
200+
/// both dimensions are 0, the API provides an image at original size. If
201+
/// dimensions are not specified, the default viewport size is 1280x720px.
202+
Future<Uint8List> getScreenshot(
203+
{required String url,
204+
Map? headers,
205+
int? viewportWidth,
206+
int? viewportHeight,
207+
double? scale,
208+
enums.Theme? theme,
209+
String? userAgent,
210+
bool? fullpage,
211+
String? locale,
212+
enums.Timezone? timezone,
213+
double? latitude,
214+
double? longitude,
215+
double? accuracy,
216+
bool? touch,
217+
List<String>? permissions,
218+
int? sleep,
219+
int? width,
220+
int? height,
221+
int? quality,
222+
enums.Output? output}) async {
223+
const String apiPath = '/avatars/screenshots';
224+
225+
final Map<String, dynamic> params = {
226+
'url': url,
227+
if (headers != null) 'headers': headers,
228+
if (viewportWidth != null) 'viewportWidth': viewportWidth,
229+
if (viewportHeight != null) 'viewportHeight': viewportHeight,
230+
if (scale != null) 'scale': scale,
231+
if (theme != null) 'theme': theme!.value,
232+
if (userAgent != null) 'userAgent': userAgent,
233+
if (fullpage != null) 'fullpage': fullpage,
234+
if (locale != null) 'locale': locale,
235+
if (timezone != null) 'timezone': timezone!.value,
236+
if (latitude != null) 'latitude': latitude,
237+
if (longitude != null) 'longitude': longitude,
238+
if (accuracy != null) 'accuracy': accuracy,
239+
if (touch != null) 'touch': touch,
240+
if (permissions != null) 'permissions': permissions,
241+
if (sleep != null) 'sleep': sleep,
242+
if (width != null) 'width': width,
243+
if (height != null) 'height': height,
244+
if (quality != null) 'quality': quality,
245+
if (output != null) 'output': output!.value,
184246
'project': client.config['project'],
185247
};
186248

0 commit comments

Comments
 (0)