forked from PalisadoesFoundation/talawa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Latest Develop 20240724 (PalisadoesFoundation#2530)
* 20240727112557 Deleted all files in the main branch in anticipation of merging develop into main cleanly * 20240727112838 Merge develop into main
- Loading branch information
1 parent
3c618a3
commit 7c520a1
Showing
101 changed files
with
2,313 additions
and
569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// The `Venue` class represents a venue for events. | ||
class Venue { | ||
/// Constructs a `Venue` instance. | ||
/// | ||
/// [id] is the unique identifier of the venue. | ||
/// [capacity] is the maximum number of people the venue can accommodate. | ||
/// [description] provides additional details about the venue. | ||
/// [imageUrl] is the URL of the venue's image. | ||
/// [name] is the name of the venue. | ||
/// [organizationId] is the identifier of the organization to which the venue belongs. | ||
Venue({ | ||
this.id, | ||
this.capacity, | ||
this.description, | ||
this.imageUrl, | ||
this.name, | ||
this.organizationId, | ||
}); | ||
|
||
/// Creates a `Venue` instance from a JSON object. | ||
/// | ||
/// The [json] parameter is a map containing the venue data. | ||
/// | ||
/// Returns an instance of `Venue`. | ||
factory Venue.fromJson(Map<String, dynamic> json) { | ||
return Venue( | ||
id: json['_id'] as String?, | ||
capacity: json['capacity'] as int?, | ||
description: json['description'] as String?, | ||
imageUrl: json['imageUrl'] as String? ?? '', | ||
name: json['name'] as String?, | ||
organizationId: | ||
(json['organization'] as Map<String, dynamic>?)?['_id'] as String?, | ||
); | ||
} | ||
|
||
/// The unique identifier of the venue. | ||
final String? id; | ||
|
||
/// The maximum number of people the venue can accommodate. | ||
final int? capacity; | ||
|
||
/// Provides additional details about the venue. | ||
final String? description; | ||
|
||
/// The URL of the venue's image. | ||
final String? imageUrl; | ||
|
||
/// The name of the venue. | ||
final String? name; | ||
|
||
/// The identifier of the organization to which the venue belongs. | ||
final String? organizationId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
lib/services/third_party_service/connectivity_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:talawa/locator.dart'; | ||
|
||
/// This class provides services related to network connectivity monitoring and handling. | ||
/// | ||
/// It includes methods for: | ||
/// * Initializing the network service - [initConnectivity] | ||
/// * Monitoring connectivity changes - [enableSubscription] | ||
/// * Handling online and offline states - [handleOnline], [handleOffline] | ||
/// * Checking reachability of a given URI - [isReachable] | ||
/// * Handling the device's connectivity status - [handleConnection] | ||
/// * Checking if the device has any type of network connection - [hasConnection] | ||
class ConnectivityService { | ||
/// Stream controller for network status changes. | ||
late StreamController<ConnectivityResult> connectionStatusController; | ||
|
||
/// Getter for the stream of connection status changes. | ||
Stream<ConnectivityResult> get connectionStream => | ||
connectionStatusController.stream; | ||
|
||
/// Checks the current internet connectivity status of the device. | ||
/// | ||
/// **params**: | ||
/// None | ||
/// | ||
/// **returns**: | ||
/// * `Future<ConnectivityResult>`: indicates if the url is reachable. | ||
Future<ConnectivityResult> getConnectionType() async { | ||
final result = await connectivity.checkConnectivity(); | ||
return result; | ||
} | ||
|
||
/// Client to access internet. | ||
late final http.Client _client; | ||
|
||
/// This function initializes connectivity monitoring. | ||
/// | ||
/// **params**: | ||
/// * `client`: An instance of `http.Client` to make the HTTP request. | ||
/// | ||
/// **returns**: | ||
/// None | ||
Future<void> initConnectivity({required http.Client client}) async { | ||
_client = client; | ||
connectionStatusController = StreamController<ConnectivityResult>(); | ||
|
||
/// Listen for future changes in connectivity | ||
enableSubscription(); | ||
} | ||
|
||
/// This function enables the subscription to connectivity changes. | ||
/// | ||
/// **params**: | ||
/// None | ||
/// | ||
/// **returns**: | ||
/// None | ||
Future<void> enableSubscription() async { | ||
connectivity.onConnectivityChanged.listen( | ||
(ConnectivityResult result) { | ||
print(result); | ||
connectionStatusController.add(result); | ||
}, | ||
onError: (error) { | ||
// Handle errors during listening for changes | ||
print('Error listening for connectivity changes: $error'); | ||
}, | ||
); | ||
} | ||
|
||
/// This function checks if a given URI is reachable within a specified timeout period. | ||
/// | ||
/// Specifically designed to | ||
/// | ||
/// **params**: | ||
/// * `client`: An instance of `http.Client` to make the HTTP request. | ||
/// * `uriString`: An optional `String` specifying the URI to check. | ||
/// Defaults to 'org link' if not provided. | ||
/// | ||
/// **returns**: | ||
/// * `Future<bool>`: indicates if the url is reachable. | ||
Future<bool> isReachable({ | ||
http.Client? client, | ||
String? uriString, | ||
}) async { | ||
try { | ||
client ??= _client; | ||
await client | ||
.get(Uri.parse(uriString ?? graphqlConfig.httpLink.uri.toString())) | ||
.timeout(const Duration(seconds: 30)); | ||
return true; | ||
} catch (e) { | ||
print('Timeout while checking reachability: $e'); | ||
return false; | ||
} | ||
} | ||
|
||
/// This function checks if the device currently has any type of network connection. | ||
/// | ||
/// **params**: | ||
/// None | ||
/// | ||
/// **returns**: | ||
/// * `Future<bool>`: indicating whether the device has a network connection. | ||
Future<bool> hasConnection() async { | ||
try { | ||
final result = await getConnectionType(); | ||
return result != ConnectivityResult.none; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.