Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 20.3.1

* Fix passing of `null` values and stripping only non-nullable optional parameters from the request body

## 20.3.0

* Add `total` parameter to list queries allowing skipping counting rows in a table for improved performance
Expand Down
65 changes: 65 additions & 0 deletions docs/examples/avatars/get-screenshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:appwrite/appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

Avatars avatars = Avatars(client);

// Downloading file
UInt8List bytes = await avatars.getScreenshot(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix type name typo.

Line 10 uses UInt8List but should be Uint8List (lowercase 'int').

Apply this diff:

-UInt8List bytes = await avatars.getScreenshot(
+Uint8List bytes = await avatars.getScreenshot(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UInt8List bytes = await avatars.getScreenshot(
Uint8List bytes = await avatars.getScreenshot(
🤖 Prompt for AI Agents
In docs/examples/avatars/get-screenshot.md around line 10, change the incorrect
type name "UInt8List" to the correct Dart type "Uint8List" (lowercase 'int');
update that occurrence (and any other occurrences in the file) so the example
compiles and matches Dart's Uint8List type name.

url: 'https://example.com',
headers: {}, // optional
viewportWidth: 1, // optional
viewportHeight: 1, // optional
scale: 0.1, // optional
theme: .light, // optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix enum reference syntax.

The enum values are referenced with a leading dot without proper qualification. In Dart, enum values must be prefixed with the enum type or imported with a prefix.

Apply this diff to fix the enum references:

-    theme: .light, // optional
+    theme: enums.Theme.light, // optional
-    timezone: .africaAbidjan, // optional
+    timezone: enums.Timezone.africaAbidjan, // optional
-    output: .jpg, // optional
+    output: enums.Output.jpg, // optional

The same corrections apply to lines 44, 48, and 58 in the second example.

Also applies to: 20-20, 30-30

🤖 Prompt for AI Agents
In docs/examples/avatars/get-screenshot.md lines 16, 20, 30, 44, 48 and 58, enum
values are referenced with a leading dot (e.g., ".light") which is invalid in
Dart; update each enum reference to be fully qualified by its enum type (for
example change ".light" to "Theme.light" or the appropriate enum name
used/imported in the example) so all enum values are properly prefixed.

userAgent: '<USER_AGENT>', // optional
fullpage: false, // optional
locale: '<LOCALE>', // optional
timezone: .africaAbidjan, // optional
latitude: -90, // optional
longitude: -180, // optional
accuracy: 0, // optional
touch: false, // optional
permissions: [], // optional
sleep: 0, // optional
width: 0, // optional
height: 0, // optional
quality: -1, // optional
output: .jpg, // optional
)

final file = File('path_to_file/filename.ext');
file.writeAsBytesSync(bytes);

// Displaying image preview
FutureBuilder(
future: avatars.getScreenshot(
url:'https://example.com' ,
headers:{} , // optional
viewportWidth:1 , // optional
viewportHeight:1 , // optional
scale:0.1 , // optional
theme: .light, // optional
userAgent:'<USER_AGENT>' , // optional
fullpage:false , // optional
locale:'<LOCALE>' , // optional
timezone: .africaAbidjan, // optional
latitude:-90 , // optional
longitude:-180 , // optional
accuracy:0 , // optional
touch:false , // optional
permissions:[] , // optional
sleep:0 , // optional
width:0 , // optional
height:0 , // optional
quality:-1 , // optional
output: .jpg, // 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();
}
);
3 changes: 3 additions & 0 deletions lib/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ part 'src/enums/o_auth_provider.dart';
part 'src/enums/browser.dart';
part 'src/enums/credit_card.dart';
part 'src/enums/flag.dart';
part 'src/enums/theme.dart';
part 'src/enums/timezone.dart';
part 'src/enums/output.dart';
part 'src/enums/execution_method.dart';
part 'src/enums/image_gravity.dart';
part 'src/enums/image_format.dart';
Expand Down
32 changes: 16 additions & 16 deletions lib/services/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Account extends Service {
'userId': userId,
'email': email,
'password': password,
'name': name,
if (name != null) 'name': name,
};

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

final Map<String, dynamic> apiParams = {
'queries': queries,
'total': total,
if (queries != null) 'queries': queries,
if (total != null) 'total': total,
};

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

final Map<String, dynamic> apiParams = {
'queries': queries,
'total': total,
if (queries != null) 'queries': queries,
if (total != null) 'total': total,
};

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

final Map<String, dynamic> apiParams = {
'password': password,
'oldPassword': oldPassword,
if (oldPassword != null) 'oldPassword': oldPassword,
};

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

final Map<String, dynamic> params = {
'success': success,
'failure': failure,
'scopes': scopes,
if (success != null) 'success': success,
if (failure != null) 'failure': failure,
if (scopes != null) 'scopes': scopes,
'project': client.config['project'],
};

Expand Down Expand Up @@ -985,7 +985,7 @@ class Account extends Service {
final Map<String, dynamic> apiParams = {
'targetId': targetId,
'identifier': identifier,
'providerId': providerId,
if (providerId != null) 'providerId': providerId,
};

final Map<String, String> apiHeaders = {
Expand Down Expand Up @@ -1062,7 +1062,7 @@ class Account extends Service {
final Map<String, dynamic> apiParams = {
'userId': userId,
'email': email,
'phrase': phrase,
if (phrase != null) 'phrase': phrase,
};

final Map<String, String> apiHeaders = {
Expand Down Expand Up @@ -1099,8 +1099,8 @@ class Account extends Service {
final Map<String, dynamic> apiParams = {
'userId': userId,
'email': email,
'url': url,
'phrase': phrase,
if (url != null) 'url': url,
if (phrase != null) 'phrase': phrase,
};

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

final Map<String, dynamic> params = {
'success': success,
'failure': failure,
'scopes': scopes,
if (success != null) 'success': success,
if (failure != null) 'failure': failure,
if (scopes != null) 'scopes': scopes,
'project': client.config['project'],
};

Expand Down
98 changes: 80 additions & 18 deletions lib/services/avatars.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class Avatars extends Service {
'/avatars/browsers/{code}'.replaceAll('{code}', code.value);

final Map<String, dynamic> params = {
'width': width,
'height': height,
'quality': quality,
if (width != null) 'width': width,
if (height != null) 'height': height,
if (quality != null) 'quality': quality,
'project': client.config['project'],
};

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

final Map<String, dynamic> params = {
'width': width,
'height': height,
'quality': quality,
if (width != null) 'width': width,
if (height != null) 'height': height,
if (quality != null) 'quality': quality,
'project': client.config['project'],
};

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

final Map<String, dynamic> params = {
'width': width,
'height': height,
'quality': quality,
if (width != null) 'width': width,
if (height != null) 'height': height,
if (quality != null) 'quality': quality,
'project': client.config['project'],
};

Expand All @@ -126,8 +126,8 @@ class Avatars extends Service {

final Map<String, dynamic> params = {
'url': url,
'width': width,
'height': height,
if (width != null) 'width': width,
if (height != null) 'height': height,
'project': client.config['project'],
};

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

final Map<String, dynamic> params = {
'name': name,
'width': width,
'height': height,
'background': background,
if (name != null) 'name': name,
if (width != null) 'width': width,
if (height != null) 'height': height,
if (background != null) 'background': background,
'project': client.config['project'],
};

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

final Map<String, dynamic> params = {
'text': text,
'size': size,
'margin': margin,
'download': download,
if (size != null) 'size': size,
if (margin != null) 'margin': margin,
if (download != null) 'download': download,
'project': client.config['project'],
};

final res = await client.call(HttpMethod.get,
path: apiPath, params: params, responseType: ResponseType.bytes);
return res.data;
}

/// Use this endpoint to capture a screenshot of any website URL. This endpoint
/// uses a headless browser to render the webpage and capture it as an image.
///
/// You can configure the browser viewport size, theme, user agent,
/// geolocation, permissions, and more. Capture either just the viewport or the
/// full page scroll.
///
/// When width and height are specified, the image is resized accordingly. If
/// both dimensions are 0, the API provides an image at original size. If
/// dimensions are not specified, the default viewport size is 1280x720px.
Future<Uint8List> getScreenshot(
{required String url,
Map? headers,
int? viewportWidth,
int? viewportHeight,
double? scale,
enums.Theme? theme,
String? userAgent,
bool? fullpage,
String? locale,
enums.Timezone? timezone,
double? latitude,
double? longitude,
double? accuracy,
bool? touch,
List<String>? permissions,
int? sleep,
int? width,
int? height,
int? quality,
enums.Output? output}) async {
const String apiPath = '/avatars/screenshots';

final Map<String, dynamic> params = {
'url': url,
if (headers != null) 'headers': headers,
if (viewportWidth != null) 'viewportWidth': viewportWidth,
if (viewportHeight != null) 'viewportHeight': viewportHeight,
if (scale != null) 'scale': scale,
if (theme != null) 'theme': theme!.value,
if (userAgent != null) 'userAgent': userAgent,
if (fullpage != null) 'fullpage': fullpage,
if (locale != null) 'locale': locale,
if (timezone != null) 'timezone': timezone!.value,
if (latitude != null) 'latitude': latitude,
if (longitude != null) 'longitude': longitude,
if (accuracy != null) 'accuracy': accuracy,
if (touch != null) 'touch': touch,
if (permissions != null) 'permissions': permissions,
if (sleep != null) 'sleep': sleep,
if (width != null) 'width': width,
if (height != null) 'height': height,
if (quality != null) 'quality': quality,
if (output != null) 'output': output!.value,
'project': client.config['project'],
};

Expand Down
Loading