diff --git a/Frontend/patient_manager/lib/main.dart b/Frontend/patient_manager/lib/main.dart index dc674548..22cfb0d3 100644 --- a/Frontend/patient_manager/lib/main.dart +++ b/Frontend/patient_manager/lib/main.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/router/routeGenerator.dart'; import 'package:patient_manager/theme/mihTheme.dart'; -import 'package:flutter_windowmanager/flutter_windowmanager.dart'; +import 'package:no_screenshot/no_screenshot.dart'; class MzanziInnovationHub extends StatefulWidget { const MzanziInnovationHub({ @@ -20,7 +20,7 @@ class MzanziInnovationHub extends StatefulWidget { class _MzanziInnovationHubState extends State { late ThemeMode _themeMode; late MyTheme theme; - + final noscreenshot = NoScreenshot.instance; Color getPrimany() { return theme.primaryColor(); } @@ -53,18 +53,15 @@ class _MzanziInnovationHubState extends State { _themeMode = ThemeMode.dark; theme = MyTheme(); theme.platform = Theme.of(context).platform; + if (theme.getPlatform() == "Android") { + noscreenshot.screenshotOff(); + } theme.mode = "Dark"; super.initState(); } @override Widget build(BuildContext context) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - if (theme.getPlatform() == "Android") { - await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE); - } - }); - double width = MediaQuery.sizeOf(context).width; theme.setScreenType(width); precacheImage(theme.loadingImage(), context); diff --git a/Frontend/patient_manager/lib/test_files/test.dart b/Frontend/patient_manager/lib/test_files/test.dart index d8c85bf1..8b137891 100644 --- a/Frontend/patient_manager/lib/test_files/test.dart +++ b/Frontend/patient_manager/lib/test_files/test.dart @@ -1,193 +1 @@ -import 'dart:async'; -import 'package:flutter/material.dart'; -import 'package:secure_application/secure_application.dart'; - -void main() => runApp(MaterialApp(home: MyApp())); - -class MyApp extends StatefulWidget { - @override - _MyAppState createState() => _MyAppState(); -} - -class _MyAppState extends State { - bool failedAuth = false; - double blurr = 20; - double opacity = 0.6; - StreamSubscription? subLock; - List history = []; - - @override - void initState() { - super.initState(); - } - - @override - void dispose() { - subLock?.cancel(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - var width = MediaQuery.of(context).size.width * 0.8; - return MaterialApp( - home: SecureApplication( - nativeRemoveDelay: 1000, - onNeedUnlock: (secure) async { - print( - 'need unlock maybe use biometric to confirm and then sercure.unlock() or you can use the lockedBuilder'); - // var authResult = authMyUser(); - // if (authResul) { - // secure.unlock(); - // return SecureApplicationAuthenticationStatus.SUCCESS; - //} - // else { - // return SecureApplicationAuthenticationStatus.FAILED; - //} - return null; - }, - onAuthenticationFailed: () async { - // clean you data - setState(() { - failedAuth = true; - }); - print('auth failed'); - }, - onAuthenticationSucceed: () async { - // clean you data - - setState(() { - failedAuth = false; - }); - print('auth success'); - }, - child: Builder(builder: (context) { - if (subLock == null) - subLock = SecureApplicationProvider.of(context, listen: false) - ?.lockEvents - .listen((s) => history.add( - '${DateTime.now().toIso8601String()} - ${s ? 'locked' : 'unlocked'}')); - return SecureGate( - blurr: blurr, - opacity: opacity, - lockedBuilder: (context, secureNotifier) => Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ElevatedButton( - child: Text('UNLOCK'), - onPressed: () => secureNotifier?.authSuccess(unlock: true), - ), - ElevatedButton( - child: Text('FAIL AUTHENTICATION'), - onPressed: () => secureNotifier?.authFailed(unlock: true), - ), - ], - )), - child: Scaffold( - appBar: AppBar( - title: const Text('Secure Window Example'), - ), - body: Center( - child: Builder(builder: (context) { - var valueNotifier = SecureApplicationProvider.of(context); - if (valueNotifier == null) - throw new Exception( - 'Unable to find secure application context'); - return ListView( - children: [ - Text('This is secure content'), - ValueListenableBuilder( - valueListenable: valueNotifier, - builder: (context, state, _) => state.secured - ? Column( - children: [ - ElevatedButton( - onPressed: () => valueNotifier.open(), - child: Text('Open app'), - ), - state.paused - ? ElevatedButton( - onPressed: () => - valueNotifier.unpause(), - child: Text('resume security'), - ) - : ElevatedButton( - onPressed: () => - valueNotifier.pause(), - child: Text('pause security'), - ), - ], - ) - : ElevatedButton( - onPressed: () => valueNotifier.secure(), - child: Text('Secure app'), - ), - ), - failedAuth - ? Text( - 'Auth failed we cleaned sensitive data', - style: TextStyle(color: Colors.red), - ) - : Text( - 'Auth success', - style: TextStyle(color: Colors.green), - ), - FlutterLogo( - size: width, - ), - StreamBuilder( - stream: valueNotifier.authenticationEvents, - builder: (context, snapshot) => - Text('Last auth status is: ${snapshot.data}'), - ), - ElevatedButton( - onPressed: () => valueNotifier.lock(), - child: Text('manually lock'), - ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - children: [ - Text('Blurr:'), - Expanded( - child: Slider( - value: blurr, - min: 0, - max: 100, - onChanged: (v) => setState(() => blurr = v)), - ), - Text(blurr.floor().toString()), - ], - ), - ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - children: [ - Text('opacity:'), - Expanded( - child: Slider( - value: opacity, - min: 0, - max: 1, - onChanged: (v) => - setState(() => opacity = v)), - ), - Text((opacity * 100).floor().toString() + "%"), - ], - ), - ), - ...history.map((h) => Text(h)).toList(), - ], - ); - }), - ), - ), - ); - }), - ), - ); - } -} \ No newline at end of file diff --git a/Frontend/patient_manager/lib/theme/mihTheme.dart b/Frontend/patient_manager/lib/theme/mihTheme.dart index b70a88c4..d3b59353 100644 --- a/Frontend/patient_manager/lib/theme/mihTheme.dart +++ b/Frontend/patient_manager/lib/theme/mihTheme.dart @@ -84,6 +84,12 @@ class MyTheme { } } else if (kIsWeb) { return "Web"; + } else if (!kIsWeb) { + if (platform == TargetPlatform.android) { + return "Android"; + } else if (platform == TargetPlatform.iOS) { + return "iOS"; + } } return "Other"; } diff --git a/Frontend/patient_manager/pubspec.lock b/Frontend/patient_manager/pubspec.lock index 61e6d018..c03826cf 100644 --- a/Frontend/patient_manager/pubspec.lock +++ b/Frontend/patient_manager/pubspec.lock @@ -400,14 +400,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_windowmanager: - dependency: "direct main" - description: - name: flutter_windowmanager - sha256: b4d0bc06f6777952b729c0cdb7ce9ad1ecabd8b8b1cb0acb57a36621457dab1b - url: "https://pub.dev" - source: hosted - version: "0.2.0" font_awesome_flutter: dependency: transitive description: @@ -696,6 +688,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.27" + no_screenshot: + dependency: "direct main" + description: + name: no_screenshot + sha256: ec3d86d7ee89a09c3a3939c1003012536ba4b3fcb4f8cbd23d87ada595c99258 + url: "https://pub.dev" + source: hosted + version: "0.3.1" package_config: dependency: transitive description: @@ -856,14 +856,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" - secure_application: - dependency: "direct main" - description: - name: secure_application - sha256: b8e34b4bc2467a3a3c0a649e46ae6a442df7ca27aeaddebb8a53c40656da0385 - url: "https://pub.dev" - source: hosted - version: "4.0.1" shared_preferences: dependency: transitive description: diff --git a/Frontend/patient_manager/pubspec.yaml b/Frontend/patient_manager/pubspec.yaml index adb76166..cb8e2baa 100644 --- a/Frontend/patient_manager/pubspec.yaml +++ b/Frontend/patient_manager/pubspec.yaml @@ -52,8 +52,7 @@ dependencies: flutter_native_splash: ^2.4.1 #google_maps_flutter_web: ^0.5.10 url_strategy: ^0.3.0 - secure_application: ^4.0.1 - flutter_windowmanager: ^0.2.0 + no_screenshot: ^0.3.1 dev_dependencies: flutter_test: