Skip to content

Commit

Permalink
image picker and web socket update
Browse files Browse the repository at this point in the history
  • Loading branch information
mirmoktadir committed Sep 2, 2023
1 parent 237f350 commit 376dbe7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
4 changes: 3 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
2337DF983062679D03D5B21B /* Pods-RunnerTests.release.xcconfig */,
4175C67EA418E1EC91AB925F /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -468,6 +467,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6FB62SU8KL;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -646,6 +646,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6FB62SU8KL;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -668,6 +669,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6FB62SU8KL;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
13 changes: 9 additions & 4 deletions lib/utils/custom_image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class CustomImagePicker {

/// Pick Image From Gallery
Future getImageFromGallery() async {
var galleryImage =
await ImagePicker().pickImage(source: ImageSource.gallery);
var galleryImage = await ImagePicker().pickImage(
source: ImageSource.gallery,
imageQuality: 50,
);

if (galleryImage != null) {
pickedImage.value = cropImage(File(galleryImage.path));
Expand All @@ -24,7 +26,10 @@ class CustomImagePicker {

/// Pick Image From Camera
Future getImageFromCamera() async {
var cameraImage = await ImagePicker().pickImage(source: ImageSource.camera);
var cameraImage = await ImagePicker().pickImage(
source: ImageSource.camera,
imageQuality: 50,
);

if (cameraImage != null) {
//pickedImage.value = cropImage(File(galleryImage.path)); "If we want to use cropped image "
Expand All @@ -46,7 +51,7 @@ class CustomImagePicker {
CropAspectRatioPreset.ratio16x9
],
cropStyle: CropStyle.circle,
compressQuality: 100,
compressQuality: 50,
compressFormat: ImageCompressFormat.png,
uiSettings: [
AndroidUiSettings(
Expand Down
34 changes: 21 additions & 13 deletions lib/utils/web_socket_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,37 @@ class WebSocketManager {
late WebSocketChannel _channel;
late WebSocket _webSocket;
RxString receivedMessage = "".obs; // This full response comes from websocket
RxInt totalClaps =
RxInt yourJsonKeyValue =
0.obs; // collecting any particular value from socket response

Future<void> connectWebSocket() async {
const String url = 'your-websocket-url';
try {
_webSocket = await WebSocket.connect(url);
_channel = IOWebSocketChannel(_webSocket);
List<String> urls = [
'your-websocket-url', // socket url 1
'your-websocket-url', // socket url 2
];
for (var url in urls) {
try {
_webSocket = await WebSocket.connect(url);
_channel = IOWebSocketChannel(_webSocket);

_channel.stream.listen((message) {
_parseReceivedMessage(message); // your particular value
receivedMessage.value = message; // main response
});
} catch (e) {
Logger().e('WebSocket connection failed: $e');
_channel.stream.listen((message) {
_parseReceivedMessage(message); // your particular value
receivedMessage.value = message; // main response
});
Logger().i('WebSocket connection established in: $url');
} catch (e) {
Logger().e('WebSocket connection failed: $e');
}
}
}

// Decoding main socket response to get particular value
void _parseReceivedMessage(String message) {
Logger().d('Received message: $message');
final Map<String, dynamic> data = jsonDecode(message);
if (data.containsKey('total_claps')) {
totalClaps.value = data['total_claps'];
if (data.containsKey('json_key')) {
yourJsonKeyValue.value = data['json_key'];
Logger().d(yourJsonKeyValue.value);
}
}

Expand Down

0 comments on commit 376dbe7

Please sign in to comment.