From ee9c5c92a70092c155cdf4cb906d6cb9fc715a51 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 3 Sep 2020 20:31:31 +0300 Subject: [PATCH] Updated Flutter SDK --- app/config/platforms.php | 2 +- app/sdks/client-flutter/CHANGELOG.md | 5 +++ app/sdks/client-flutter/README.md | 2 +- app/sdks/client-flutter/lib/client.dart | 44 ++++++++++++------- .../client-flutter/lib/services/avatars.dart | 24 ++++++++++ .../client-flutter/lib/services/storage.dart | 12 +++++ app/sdks/client-flutter/pubspec.yaml | 27 +++--------- docs/sdks/flutter/CHANGELOG.md | 2 +- 8 files changed, 78 insertions(+), 40 deletions(-) diff --git a/app/config/platforms.php b/app/config/platforms.php index aac118079..c3d09fac1 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -30,7 +30,7 @@ return [ [ 'key' => 'flutter', 'name' => 'Flutter', - 'version' => '0.2.3', + 'version' => '0.3.0-dev.1', 'url' => 'https://github.com/appwrite/sdk-for-flutter', 'enabled' => true, 'beta' => true, diff --git a/app/sdks/client-flutter/CHANGELOG.md b/app/sdks/client-flutter/CHANGELOG.md index c9013a17e..638d0882d 100644 --- a/app/sdks/client-flutter/CHANGELOG.md +++ b/app/sdks/client-flutter/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.3.0-dev.1 + +- Updated package dependencies (@lohanidamodar) +- Added Flutter for Web compatibility (@lohanidamodar) + ## 0.2.3 - Fixed OAuth2 cookie bug, where a new session cookie couldn't overwrite an old cookie diff --git a/app/sdks/client-flutter/README.md b/app/sdks/client-flutter/README.md index 877cf5d30..95cdeae64 100644 --- a/app/sdks/client-flutter/README.md +++ b/app/sdks/client-flutter/README.md @@ -20,7 +20,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^0.2.3 + appwrite: ^0.3.0-dev.1 ``` You can install packages from the command line: diff --git a/app/sdks/client-flutter/lib/client.dart b/app/sdks/client-flutter/lib/client.dart index 7a53d0414..1cf3ac8f0 100644 --- a/app/sdks/client-flutter/lib/client.dart +++ b/app/sdks/client-flutter/lib/client.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart'; import 'package:dio/adapter.dart'; import 'package:dio_cookie_manager/dio_cookie_manager.dart'; import 'package:cookie_jar/cookie_jar.dart'; @@ -20,17 +21,21 @@ class Client { PersistCookieJar cookieJar; Client({this.endPoint = 'https://appwrite.io/v1', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() { - - type = (Platform.isIOS) ? 'ios' : type; - type = (Platform.isMacOS) ? 'macos' : type; - type = (Platform.isAndroid) ? 'android' : type; - type = (Platform.isLinux) ? 'linux' : type; - type = (Platform.isWindows) ? 'windows' : type; - type = (Platform.isFuchsia) ? 'fuchsia' : type; + // Platform is not supported in web so if web, set type to web automatically and skip Platform check + if(kIsWeb) { + type = 'web'; + }else{ + type = (Platform.isIOS) ? 'ios' : type; + type = (Platform.isMacOS) ? 'macos' : type; + type = (Platform.isAndroid) ? 'android' : type; + type = (Platform.isLinux) ? 'linux' : type; + type = (Platform.isWindows) ? 'windows' : type; + type = (Platform.isFuchsia) ? 'fuchsia' : type; + } this.headers = { 'content-type': 'application/json', - 'x-sdk-version': 'appwrite:dart:0.2.3', + 'x-sdk-version': 'appwrite:flutter:0.3.0-dev.1', }; this.config = {}; @@ -78,17 +83,20 @@ class Client { Future init() async { if(!initialized) { - final Directory cookieDir = await _getCookiePath(); - - cookieJar = new PersistCookieJar(dir:cookieDir.path); + // if web skip cookie implementation and origin header as those are automatically handled by browsers + if(!kIsWeb) { + final Directory cookieDir = await _getCookiePath(); + cookieJar = new PersistCookieJar(dir:cookieDir.path); + this.http.interceptors.add(CookieManager(cookieJar)); + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + addHeader('Origin', 'appwrite-' + type + '://' + packageInfo.packageName); + }else{ + // if web set httpClientAdapter as BrowserHttpClientAdapter with withCredentials true to make cookies work + this.http.options.extra['withCredentials'] = true; + } this.http.options.baseUrl = this.endPoint; this.http.options.validateStatus = (status) => status < 400; - this.http.interceptors.add(CookieManager(cookieJar)); - - PackageInfo packageInfo = await PackageInfo.fromPlatform(); - - addHeader('Origin', 'appwrite-' + type + '://' + packageInfo.packageName); } } @@ -114,6 +122,10 @@ class Client { } if (method == HttpMethod.get) { + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + return http.get(path, queryParameters: params, options: options); } else { return http.request(path, data: params, options: options); diff --git a/app/sdks/client-flutter/lib/services/avatars.dart b/app/sdks/client-flutter/lib/services/avatars.dart index fc9c403d9..828ea7dfb 100644 --- a/app/sdks/client-flutter/lib/services/avatars.dart +++ b/app/sdks/client-flutter/lib/services/avatars.dart @@ -27,6 +27,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -55,6 +59,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -79,6 +87,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -106,6 +118,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -134,6 +150,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -161,6 +181,10 @@ class Avatars extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, diff --git a/app/sdks/client-flutter/lib/services/storage.dart b/app/sdks/client-flutter/lib/services/storage.dart index 696c15ee3..51f934505 100644 --- a/app/sdks/client-flutter/lib/services/storage.dart +++ b/app/sdks/client-flutter/lib/services/storage.dart @@ -124,6 +124,10 @@ class Storage extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -154,6 +158,10 @@ class Storage extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, @@ -178,6 +186,10 @@ class Storage extends Service { 'project': client.config['project'], }; + params.keys.forEach((key) {if (params[key] is int || params[key] is double) { + params[key] = params[key].toString(); + }}); + Uri endpoint = Uri.parse(client.endPoint); Uri location = new Uri(scheme: endpoint.scheme, host: endpoint.host, diff --git a/app/sdks/client-flutter/pubspec.yaml b/app/sdks/client-flutter/pubspec.yaml index 91a884cd2..2d0c2fe41 100644 --- a/app/sdks/client-flutter/pubspec.yaml +++ b/app/sdks/client-flutter/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 0.2.3 +version: 0.3.0-dev.1 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 homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-flutter @@ -9,30 +9,15 @@ environment: sdk: '>=2.6.0 <3.0.0' dependencies: meta: ^1.1.8 - path_provider: ^1.6.5 - package_info: ^0.4.0+16 - dio: ^3.0.0 - cookie_jar: ^1.0.0 + path_provider: ^1.6.14 + package_info: ^0.4.3 + dio: ^3.0.10 + cookie_jar: ^1.0.1 dio_cookie_manager: ^1.0.0 flutter_web_auth: ^0.2.4 flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 - dev_dependencies: flutter_test: - sdk: flutter - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. -flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. - uses-material-design: true \ No newline at end of file + sdk: flutter \ No newline at end of file diff --git a/docs/sdks/flutter/CHANGELOG.md b/docs/sdks/flutter/CHANGELOG.md index 945f6088a..c252451f3 100644 --- a/docs/sdks/flutter/CHANGELOG.md +++ b/docs/sdks/flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.3.0 +## 0.3.0-dev.1 - Updated package dependencies (@lohanidamodar) - Added Flutter for Web compatibility (@lohanidamodar)