From a44f58280d7032980044bbaa88eff47716178ddf Mon Sep 17 00:00:00 2001 From: FaizHashmiCS22 Date: Thu, 27 Jul 2023 09:13:24 +0300 Subject: [PATCH] Added the wakelock --- .../example/queuing_system/MainActivity.kt | 16 +++--- lib/core/api.dart | 8 +++ lib/core/response_model/patient_call.dart | 4 +- lib/home/home_screen.dart | 25 ++++----- lib/main.dart | 9 ++++ lib/utils/call_type.dart | 52 +++++++++---------- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 48 ++++++++++++++--- pubspec.yaml | 3 +- 9 files changed, 107 insertions(+), 60 deletions(-) diff --git a/android/app/src/main/kotlin/com/example/queuing_system/MainActivity.kt b/android/app/src/main/kotlin/com/example/queuing_system/MainActivity.kt index 4ee382f..1a6cfab 100644 --- a/android/app/src/main/kotlin/com/example/queuing_system/MainActivity.kt +++ b/android/app/src/main/kotlin/com/example/queuing_system/MainActivity.kt @@ -12,13 +12,13 @@ class MainActivity: FlutterActivity() { @RequiresApi(Build.VERSION_CODES.M) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - var REQUEST_OVERLAY_PERMISSIONS = 100 - if (!Settings.canDrawOverlays(applicationContext)) { - val myIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) - val uri: Uri = Uri.fromParts("package", packageName, null) - myIntent.data = uri - startActivityForResult(myIntent, REQUEST_OVERLAY_PERMISSIONS) - return - } +// var REQUEST_OVERLAY_PERMISSIONS = 100 +// if (!Settings.canDrawOverlays(applicationContext)) { +// val myIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) +// val uri: Uri = Uri.fromParts("package", packageName, null) +// myIntent.data = uri +// startActivityForResult(myIntent, REQUEST_OVERLAY_PERMISSIONS) +// return +// } } } diff --git a/lib/core/api.dart b/lib/core/api.dart index 32f88c2..11dc593 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -1,4 +1,5 @@ import 'dart:developer'; +import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:queuing_system/core/base/base_app_client.dart'; @@ -7,6 +8,13 @@ import 'package:queuing_system/core/response_model/patient_call.dart'; const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByIP"; const _call_UpdateNotIsQueueRecordByIDAsync = "/UpdateCallRequestQueue"; +class MyHttpOverrides extends HttpOverrides { + @override + HttpClient createHttpClient(SecurityContext context) { + return super.createHttpClient(context)..badCertificateCallback = (X509Certificate cert, String host, int port) => true; + } +} + class API { static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List, List) onSuccess, @required Function(dynamic) onFailure}) async { final body = {"IPAdress": deviceIp}; diff --git a/lib/core/response_model/patient_call.dart b/lib/core/response_model/patient_call.dart index c126cbb..a3e9129 100644 --- a/lib/core/response_model/patient_call.dart +++ b/lib/core/response_model/patient_call.dart @@ -30,7 +30,7 @@ class Tickets { id = json['ID']; callNo = json['CallNo']; roomNo = json['RoomNo']; - callType = json['callType']; + callType = json['CallType']; createdON = json['CreatedON']; doctorName = json['DoctorName']; doctorNameN = json['DoctorNameN']; @@ -94,7 +94,7 @@ class Tickets { } CallType getCallType() { - if (callType == 0) return CallType.RECEPTION; + if (callType == 3) return CallType.RECEPTION; if (callType == 1) return CallType.NURSE; if (callType == 2) return CallType.DOCTOR; return CallType.NONE; diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 7481672..86b6220 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer'; import 'dart:io'; @@ -18,7 +19,6 @@ import 'package:queuing_system/widget/data_display/app_texts_widget.dart'; var DEVICE_IP = "10.10.15.11"; // Testing IP -String globalInterface = ""; // var DEVICE_IP = "10.10.14.11"; // Testing IP // var DEVICE_IP = "10.10.15.11"; @@ -46,28 +46,28 @@ class _MyHomePageState extends State { super.dispose(); } - Future printIps() async { + Future printIps() async { for (var interface in await NetworkInterface.list(type: InternetAddressType.IPv4)) { - print("interfaces: ${interface.name}"); - globalInterface = globalInterface + " ** " + interface.name; - + log("interfaces: ${interface.name}"); if (interface.name == "eth0") { for (var address in interface.addresses) { DEVICE_IP = address.address; - log('${address.address} ${address.type.name}'); - log(DEVICE_IP); + return DEVICE_IP; } } + return ""; } } @override void initState() { listenNetworkConnectivity(); - printIps(); - if (!signalRHelper.getConnectionState()) { - signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect); - } + scheduleMicrotask(() async { + if (!signalRHelper.getConnectionState()) { + signalRHelper.startSignalRConnection(await printIps(), onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect); + } + }); + super.initState(); } @@ -99,7 +99,6 @@ class _MyHomePageState extends State { fontFamily: 'Poppins-Medium.ttf', ), Text(DEVICE_IP, style: TextStyle(fontWeight: FontWeight.w500, fontSize: SizeConfig.getWidthMultiplier() * 2.2)), - ], ), const SizedBox(width: 10), @@ -107,8 +106,6 @@ class _MyHomePageState extends State { "assets/images/cloud_logo.png", height: SizeConfig.getHeightMultiplier() * 4, ), - const SizedBox(width: 10), - Text(globalInterface, style: TextStyle(fontWeight: FontWeight.w500, fontSize: SizeConfig.getWidthMultiplier() * 2.2)), ], ), ], diff --git a/lib/main.dart b/lib/main.dart index f613721..ab47d96 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,11 +1,20 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:queuing_system/core/api.dart'; +import 'package:wakelock/wakelock.dart'; import 'core/base/project_view_model.dart'; import 'core/config/size_config.dart'; import 'home/home_screen.dart'; // import 'home/home_screen_bkp.dart'; void main() { + + //TODO: WE HAVE TO UPDATE THIS BEFORE GOING LIVE. + HttpOverrides.global = MyHttpOverrides(); + WidgetsFlutterBinding.ensureInitialized(); + Wakelock.enable(); runApp(const MyApp()); } diff --git a/lib/utils/call_type.dart b/lib/utils/call_type.dart index b3cfb99..7749253 100644 --- a/lib/utils/call_type.dart +++ b/lib/utils/call_type.dart @@ -1,60 +1,60 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:queuing_system/core/config/config.dart'; -enum CallType{ +enum CallType { RECEPTION, NURSE, DOCTOR, NONE, } -extension xCallType on CallType{ - - Color color(){ - if(this == CallType.RECEPTION) { +extension xCallType on CallType { + Color color() { + if (this == CallType.RECEPTION) { return AppGlobal.appRedColor; - }else if(this == CallType.NURSE) { + } else if (this == CallType.NURSE) { return AppGlobal.appGreenColor; - }else if(this == CallType.DOCTOR) { - return AppGlobal.appRedColor ; - }else{ + } else if (this == CallType.DOCTOR) { + return AppGlobal.appRedColor; + } else { return Colors.black54; } } - SvgPicture icon(double height,){ - if(this == CallType.RECEPTION) { + SvgPicture icon( + double height, + ) { + if (this == CallType.RECEPTION) { return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); - }else if(this == CallType.NURSE) { + } else if (this == CallType.NURSE) { return SvgPicture.asset("assets/images/nurseicon.svg", height: height, color: color()); - }else if(this == CallType.DOCTOR) { + } else if (this == CallType.DOCTOR) { return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); } - return SvgPicture.asset("assets/images/wait.svg", height: height, color: color());; + return SvgPicture.asset("assets/images/wait.svg", height: height, color: color()); + ; } - String message(String lang){ - if(this == CallType.RECEPTION) { - return "Please visit reception"; - }else if(this == CallType.NURSE) { + String message(String lang) { + if (this == CallType.RECEPTION) { + return "Please wait . . ."; + } else if (this == CallType.NURSE) { return "Please visit nurse"; - }else if(this == CallType.DOCTOR) { + } else if (this == CallType.DOCTOR) { return "Please visit doctor"; } return "Please wait . . ."; } - String audio(String lang){ - if(this == CallType.RECEPTION) { + String audio(String lang) { + if (this == CallType.RECEPTION) { return "visit_doctor.mp3"; - }else if(this == CallType.NURSE) { + } else if (this == CallType.NURSE) { return "visit_nurse.mp3"; - }else if(this == CallType.DOCTOR) { + } else if (this == CallType.DOCTOR) { return "visit_doctor.mp3"; } return ""; } -} \ No newline at end of file +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 950f73d..caf5f62 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import connectivity_macos import flutter_tts import just_audio import path_provider_foundation +import wakelock_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) @@ -17,4 +18,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterTtsPlugin.register(with: registry.registrar(forPlugin: "FlutterTtsPlugin")) JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 1acad53..1611713 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -184,14 +184,6 @@ packages: description: flutter source: sdk version: "0.0.0" - get_ip_address: - dependency: "direct main" - description: - name: get_ip_address - sha256: "50265edb9b1c917a29c741f3173c0dca34d8e0fc2984aed87c58f0269bf93f29" - url: "https://pub.dev" - source: hosted - version: "0.0.5" get_it: dependency: "direct main" description: @@ -525,6 +517,46 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + wakelock: + dependency: "direct main" + description: + name: wakelock + sha256: "769ecf42eb2d07128407b50cb93d7c10bd2ee48f0276ef0119db1d25cc2f87db" + url: "https://pub.dev" + source: hosted + version: "0.6.2" + wakelock_macos: + dependency: transitive + description: + name: wakelock_macos + sha256: "047c6be2f88cb6b76d02553bca5a3a3b95323b15d30867eca53a19a0a319d4cd" + url: "https://pub.dev" + source: hosted + version: "0.4.0" + wakelock_platform_interface: + dependency: transitive + description: + name: wakelock_platform_interface + sha256: "1f4aeb81fb592b863da83d2d0f7b8196067451e4df91046c26b54a403f9de621" + url: "https://pub.dev" + source: hosted + version: "0.3.0" + wakelock_web: + dependency: transitive + description: + name: wakelock_web + sha256: "1b256b811ee3f0834888efddfe03da8d18d0819317f20f6193e2922b41a501b5" + url: "https://pub.dev" + source: hosted + version: "0.4.0" + wakelock_windows: + dependency: transitive + description: + name: wakelock_windows + sha256: "857f77b3fe6ae82dd045455baa626bc4b93cb9bb6c86bf3f27c182167c3a5567" + url: "https://pub.dev" + source: hosted + version: "0.2.1" web_socket_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9fe5deb..a21c7a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,8 +41,7 @@ dependencies: blinking_text: ^1.0.2 just_audio: ^0.9.31 flutter_tts: ^3.6.3 - get_ip_address: ^0.0.5 - + wakelock: ^0.6.2 #signalr core signalr_core: ^1.1.1