diff --git a/CHANGELOG.md b/CHANGELOG.md index 5349144..216108a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 2.0.0 +- dart sdk updated: >=2.12.0 <3.0.0 (null safety) +- web support +- useDefaultLogger: default as false +- fix: accepting non-maps types on the "body" field of an update request +- other adjustments/fixes +- documentation and README changes +- code refactoring +- unit tests added +- examples updated to null safety +- new dependencies in pubspec.yaml + ## 1.0.1 - Fix: prevent old connections data from getting in the way of the last successful connection attempt diff --git a/README.md b/README.md index b2bba41..122a2c7 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ pubspec.yaml: sdk: flutter # Add this line: - askless: ^1.0.1 + askless: ^2.0.0 4 - Import the package diff --git a/README_PORTUGUES.md b/README_PORTUGUES.md index 9fdf5b0..ef7f0ef 100644 --- a/README_PORTUGUES.md +++ b/README_PORTUGUES.md @@ -61,7 +61,7 @@ pubspec.yaml: sdk: flutter # Adicione essa linha: - askless: ^1.0.1 + askless: ^2.0.0 4 - Importe diff --git a/documentation/english_documentation.md b/documentation/english_documentation.md index 247368a..5296f05 100644 --- a/documentation/english_documentation.md +++ b/documentation/english_documentation.md @@ -31,7 +31,7 @@ The URL of the server, must start with `ws://` or `wss://`. Example: `ws://192.1 #### logger - Allow to customize the behavior of internal logs and enable/disable the default logger (optional). + Allow to customize the behavior of internal logs and enable the default logger (optional). ##### Params: diff --git a/example/catalog/android/app/build.gradle b/example/catalog/android/app/build.gradle index 9cd7401..68a713e 100644 --- a/example/catalog/android/app/build.gradle +++ b/example/catalog/android/app/build.gradle @@ -33,7 +33,6 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.catalog" minSdkVersion 16 targetSdkVersion 30 @@ -43,9 +42,7 @@ android { buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig signingConfigs.debug } } } diff --git a/example/catalog/lib/main.dart b/example/catalog/lib/main.dart index 7677d19..d7e0c4e 100644 --- a/example/catalog/lib/main.dart +++ b/example/catalog/lib/main.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'CatalogMainPage.dart'; -final String ipv4Address = '192.168.2.1'; +final String ipv4Address = '192.168.0.3'; final serverUrl = 'ws://'+ipv4Address+':3000'; diff --git a/example/chat/android/app/build.gradle b/example/chat/android/app/build.gradle index 0de2c46..a3f4fbd 100644 --- a/example/chat/android/app/build.gradle +++ b/example/chat/android/app/build.gradle @@ -33,7 +33,6 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.chat" minSdkVersion 16 targetSdkVersion 30 @@ -43,8 +42,6 @@ android { buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } diff --git a/example/chat/lib/main.dart b/example/chat/lib/main.dart index 20027e2..b8098b3 100644 --- a/example/chat/lib/main.dart +++ b/example/chat/lib/main.dart @@ -3,7 +3,7 @@ import 'package:askless/askless.dart'; import 'SignInPage.dart'; -final String ipv4Address = '192.168.2.1'; +final String ipv4Address = '192.168.0.3'; final serverUrl = 'ws://'+ipv4Address+':3000'; void main() { diff --git a/example/tracking/android/app/build.gradle b/example/tracking/android/app/build.gradle index 7c87b91..221eec6 100644 --- a/example/tracking/android/app/build.gradle +++ b/example/tracking/android/app/build.gradle @@ -33,7 +33,6 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.tracking" minSdkVersion 16 targetSdkVersion 30 @@ -43,7 +42,6 @@ android { buildTypes { release { - // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } diff --git a/example/tracking/lib/main.dart b/example/tracking/lib/main.dart index 361c1b7..6013acd 100644 --- a/example/tracking/lib/main.dart +++ b/example/tracking/lib/main.dart @@ -4,7 +4,7 @@ import 'package:askless/askless.dart'; import 'TrackingApp.dart'; -final serverUrl = 'ws://192.168.2.1:3000'; +final serverUrl = 'ws://192.168.0.3:3000'; void main() { AsklessClient.instance.init( diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 8e3c61d..e1b6ae4 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -13,6 +13,10 @@ const REQUEST_PREFIX = 'REQ-'; const LISTEN_PREFIX = 'LIS-'; const CLIENT_GENERATED_ID_PREFIX = 'CLIENT_GENERATED_ID-'; -//TODO onupdate: -const CLIENT_LIBRARY_VERSION_NAME = '1.0.1'; -const CLIENT_LIBRARY_VERSION_CODE = 2; +// TODO onupdate: +const CLIENT_LIBRARY_VERSION_NAME = '2.0.0'; +const CLIENT_LIBRARY_VERSION_CODE = 3; + +// TODO onupdate: CHECK README EN / PT (# Add this line: askless: ^2.0.0) + +// TODO onupdate: add changelog \ No newline at end of file diff --git a/lib/src/index.dart b/lib/src/index.dart index eb145c9..20317f6 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -56,7 +56,7 @@ LoggerFunction _getDefaultLogger() => (String message, Level level, {additionalD class Logger{ late final LoggerFunction doLog; - /// Allow to customize the behavior of internal logs and enable/disable the default logger (optional). + /// Allow to customize the behavior of internal logs and enable the default logger (optional). /// /// [useDefaultLogger] If [true]: the default logger will be used (optional). Default: `false` /// @@ -190,6 +190,8 @@ class AsklessClient { /// Try to perform a connection with the server. /// + /// Returns the result of the connection attempt. + /// /// [ownClientId]: The ID of the user defined in your application. /// This field must NOT be [null] when the user is logging in, /// otherwise must be [null] (optional). @@ -197,11 +199,6 @@ class AsklessClient { /// [headers]: Allows informing the token of the respective [ownClientId] (and/or additional data) /// so that the server can be able to accept or deny the connection attempt (optional). /// - /// In the server side, you can implement [grantConnection](https://github.com/WiseTap/askless/blob/master/documentation/english_documentation.md#grantconnection) - /// to accept or deny connections attempts from the client. - /// - /// Returns the result of the connection attempt. - /// /// Example: /// ``` /// AsklessClient.instance.connect(ownClientId: 1, headers: { @@ -290,6 +287,17 @@ class AsklessClient { /// If [false]: the field [requestTimeoutInSeconds] defined in the server side /// will be the timeout. /// + /// Example + /// ``` + /// AsklessClient.instance + /// .create(route: 'product', + /// body: { + /// 'name' : 'Video Game', + /// 'price' : 500, + /// 'discount' : 0.1 + /// } + /// ).then((res) => print(res.isSuccess ? 'Success' : res.error!.code)); + /// ``` Future create({required String route, required dynamic body, Map ? query, bool neverTimeout: false}) async { assert(body!=null); await _assertHasMadeConnection(); @@ -313,6 +321,19 @@ class AsklessClient { /// If [false]: the field [requestTimeoutInSeconds] defined in the server side /// will be the timeout. /// + /// Example + /// ``` + /// AsklessClient.instance + /// .update( + /// route: 'allProducts', + /// query: { + /// 'nameContains' : 'game' + /// }, + /// body: { + /// 'discount' : 0.8 + /// } + /// ).then((res) => print(res.isSuccess ? 'Success' : res.error!.code)); + /// ``` Future update({required String route, required dynamic body, Map ? query, bool neverTimeout: false}) async { assert(body!=null); await _assertHasMadeConnection(); @@ -366,7 +387,6 @@ class AsklessClient { /// will be the timeout. /// /// Example - /// /// ``` /// AsklessClient.instance /// .read(route: 'allProducts', @@ -402,6 +422,38 @@ class AsklessClient { /// here can be added a filter to indicate to the server /// which data this client will receive. /// + /// Example + /// ``` + /// Listening listeningForNewGamingProducts; + /// + /// @override + /// void initState() { + /// super.initState(); + /// listeningForNewGamingProducts = AsklessClient.instance + /// .listen(route: 'allProducts', + /// query: { + /// 'nameContains' : 'game' + /// }, + /// ); + /// listeningForNewGamingProducts.stream.listen((newRealtimeData) { + /// List products = newRealtimeData.output; + /// products.forEach((singleProduct) { + /// print("New gaming product created: "+singleProduct['name']); + /// }); + /// }); + /// } + /// + /// @override + /// void dispose() { + /// + /// // IMPORTANT + /// // don't forget to close the stream + /// // to stop receiving data from the server + /// listeningForNewGamingProducts.close(); + /// + /// super.dispose(); + /// } + /// ``` Listening listen({required String route, Map ? query,}) { _assertHasMadeConnection(); @@ -535,7 +587,7 @@ class AsklessClient { /// /// [serverUrl] The URL of the server, must start with [ws://] or [wss://]. Example: [ws://192.168.2.1:3000]. /// - /// [logger] Allow to customize the behavior of internal logs and enable/disable the default logger (optional). + /// [logger] Allow to customize the behavior of internal logs and enable the default logger (optional). /// /// [projectName] Name for this project (optional). /// If [!= null]: the field [projectName] on server side must have the same name (optional). @@ -567,7 +619,7 @@ typedef OnDisconnect({RespondError error}); /// Example: in [dispose] implementation of Scaffold /// that uses this stream. /// -/// [close] Stop receiving realtime data from server using [Listening.stream]. +/// [close] Stop receiving realtime data from server using [Listening.stream]. /// class Listening { /// Listening for new data from the server after call the method [wsListen]. @@ -579,7 +631,7 @@ class Listening { /// Example: in [dispose] implementation of Scaffold /// that uses this stream. /// - /// [close] Stop receiving realtime data from server using [Listening.stream]. + /// [close] Stop receiving realtime data from server using [Listening.stream]. /// final String clientRequestId; //Um id gerado pelo cliente que representa diff --git a/pubspec.yaml b/pubspec.yaml index 781fd8c..f4018fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: askless description: Flutter client of Askless framework, which facilitates building realtime servers for JavaScript and Flutter Apps -version: 1.0.1 # TODO onupdate: +version: 2.0.0 # TODO onupdate: environment: sdk: ">=2.12.0 <3.0.0" @@ -23,6 +23,8 @@ dependencies: web_socket_channel: ^2.1.0 injectable: ^1.4.1 get_it: ^7.2.0 + collection: ^1.15.0 + meta: ^1.3.0 dev_dependencies: test: ^1.17.10