adjust screen drightness on card open

This commit is contained in:
2025-08-21 12:11:17 +02:00
parent bf653e6456
commit 2424b31c75
9 changed files with 189 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools">
<!-- <uses-permission android:name="com.google.android.gms.permission.AD_ID"
tools:node="merge"/> -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
@@ -42,6 +43,21 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="flutter-deeplink"
android:value="true"
/>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.View" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="app.mzansi-innovation-hub.co.za" />
<data
android:scheme="https"
android:host="app.mzansi-innovation-hub.co.za" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

View File

@@ -65,6 +65,8 @@ PODS:
- FlutterMacOS
- printing (1.0.0):
- Flutter
- screen_brightness_ios (0.1.0):
- Flutter
- SDWebImage (5.20.0):
- SDWebImage/Core (= 5.20.0)
- SDWebImage/Core (5.20.0)
@@ -96,6 +98,7 @@ DEPENDENCIES:
- mobile_scanner (from `.symlinks/plugins/mobile_scanner/darwin`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- printing (from `.symlinks/plugins/printing/ios`)
- screen_brightness_ios (from `.symlinks/plugins/screen_brightness_ios/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- syncfusion_flutter_pdfviewer (from `.symlinks/plugins/syncfusion_flutter_pdfviewer/ios`)
@@ -138,6 +141,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
printing:
:path: ".symlinks/plugins/printing/ios"
screen_brightness_ios:
:path: ".symlinks/plugins/screen_brightness_ios/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_foundation:
@@ -167,6 +172,7 @@ SPEC CHECKSUMS:
mobile_scanner: 9157936403f5a0644ca3779a38ff8404c5434a93
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
printing: 54ff03f28fe9ba3aa93358afb80a8595a071dd07
screen_brightness_ios: 9953fd7da5bd480f1a93990daeec2eb42d4f3b52
SDWebImage: 73c6079366fea25fa4bb9640d5fb58f0893facd8
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7

View File

@@ -1,5 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_banner_ad.dart';
@@ -20,6 +22,7 @@ import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.da
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_display.dart';
import 'package:flutter/material.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:screen_brightness/screen_brightness.dart';
class BuildLoyaltyCardList extends StatefulWidget {
final AppUser signedInUser;
@@ -49,6 +52,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
final TextEditingController _nicknameController = TextEditingController();
final TextEditingController _cardNumberController = TextEditingController();
late int _noFavourites;
double? _originalBrightness;
final _formKey = GlobalKey<FormState>();
void openscanner() async {
@@ -474,10 +478,11 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
},
),
],
onWindowTapClose: widget.onCardViewClose ??
() {
Navigator.pop(context);
},
onWindowTapClose: () {
widget.onCardViewClose;
resetScreenBrightness();
context.pop();
},
windowBody: Column(
mainAxisSize: MainAxisSize.max,
children: [
@@ -561,6 +566,99 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
return count;
}
Future<void> setScreenBrightness(double newBrightness) async {
if (!kIsWeb) {
bool canChange =
await ScreenBrightness.instance.canChangeSystemBrightness;
KenLogger.success("Can change system brightness: $canChange");
if (canChange) {
// Permission is granted, you can now change the system brightness
ScreenBrightness.instance.system.then((brightness) {
setState(() {
_originalBrightness = brightness;
});
KenLogger.success("Original brightness: $_originalBrightness");
});
await ScreenBrightness.instance
.setSystemScreenBrightness(newBrightness);
KenLogger.success("Brightness set to: $newBrightness");
} else {
context.pop();
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.brightness_7_rounded,
size: 150,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Permission Required",
alertBody: Column(
children: [
Text(
"Sometimes it can be tough to scan your loyalty card if your phone screen is dim. To make sure your scan is successful every time, we need your permission to temporarily increase your screen brightness.\n\nWould you mind enabling this in your device settings?",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
MihButton(
onPressed: () async {
context.pop();
await ScreenBrightness.instance
.setSystemScreenBrightness(newBrightness);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Grant Permission",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
),
alertColour: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
},
);
}
} else {
KenLogger.warning(
"Screen brightness adjustment is not supported on Web.");
// _originalBrightness = 1.0; // Default brightness for web
// await ScreenBrightness.instance.setSystemScreenBrightness(1.0);
// KenLogger.success("Brightness set to default value: 1.0");
}
}
void resetScreenBrightness() async {
if (!kIsWeb) {
KenLogger.success(
"Resetting screen brightness to original value: $_originalBrightness");
if (_originalBrightness != null) {
await ScreenBrightness.instance
.setSystemScreenBrightness(_originalBrightness!);
}
} else {
KenLogger.warning("Screen brightness reset is not supported on Web.");
}
}
@override
void initState() {
super.initState();
@@ -596,6 +694,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
height: 100,
),
onTap: () {
setScreenBrightness(1.0);
viewCardWindow(index, size.width);
},
);

View File

@@ -461,7 +461,7 @@ class _MihCardsState extends State<MihCards> {
setState(() {
_bannerAd = MihBannerAd();
});
Navigator.pop(context);
// Navigator.pop(context);
},
);
},

View File

@@ -14,6 +14,7 @@ import local_auth_darwin
import mobile_scanner
import path_provider_foundation
import printing
import screen_brightness_macos
import share_plus
import shared_preferences_foundation
import syncfusion_pdfviewer_macos
@@ -30,6 +31,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SyncfusionFlutterPdfViewerPlugin.register(with: registry.registrar(forPlugin: "SyncfusionFlutterPdfViewerPlugin"))

View File

@@ -1072,6 +1072,62 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.2"
screen_brightness:
dependency: "direct main"
description:
name: screen_brightness
sha256: b6cb9381b83fef7be74187ea043d54598b9a265b4ef6e40b69345ae28699b13e
url: "https://pub.dev"
source: hosted
version: "2.1.6"
screen_brightness_android:
dependency: transitive
description:
name: screen_brightness_android
sha256: fb5fa43cb89d0c9b8534556c427db1e97e46594ac5d66ebdcf16063b773d54ed
url: "https://pub.dev"
source: hosted
version: "2.1.2"
screen_brightness_ios:
dependency: transitive
description:
name: screen_brightness_ios
sha256: "2493953340ecfe8f4f13f61db50ce72533a55b0bbd58ba1402893feecf3727f5"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
screen_brightness_macos:
dependency: transitive
description:
name: screen_brightness_macos
sha256: "4edf330ad21078686d8bfaf89413325fbaf571dcebe1e89254d675a3f288b5b9"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
screen_brightness_ohos:
dependency: transitive
description:
name: screen_brightness_ohos
sha256: af2680660f7df785bcd2b1bef9b9f3c172191166dd27098f2dfe020c50c3dea4
url: "https://pub.dev"
source: hosted
version: "2.1.1"
screen_brightness_platform_interface:
dependency: transitive
description:
name: screen_brightness_platform_interface
sha256: "737bd47b57746bc4291cab1b8a5843ee881af499514881b0247ec77447ee769c"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
screen_brightness_windows:
dependency: transitive
description:
name: screen_brightness_windows
sha256: d3518bf0f5d7a884cee2c14449ae0b36803802866de09f7ef74077874b6b2448
url: "https://pub.dev"
source: hosted
version: "2.1.0"
scroll_to_index:
dependency: transitive
description:

View File

@@ -49,6 +49,7 @@ dependencies:
country_code_picker: ^3.3.0
ken_logger: ^0.0.3
go_router: ^16.1.0
screen_brightness: ^2.1.6
dev_dependencies:
flutter_test:

View File

@@ -11,6 +11,7 @@
#include <geolocator_windows/geolocator_windows.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <printing/printing_plugin.h>
#include <screen_brightness_windows/screen_brightness_windows_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <syncfusion_pdfviewer_windows/syncfusion_pdfviewer_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
@@ -26,6 +27,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
PrintingPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PrintingPlugin"));
ScreenBrightnessWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
SyncfusionPdfviewerWindowsPluginRegisterWithRegistrar(

View File

@@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
geolocator_windows
local_auth_windows
printing
screen_brightness_windows
share_plus
syncfusion_pdfviewer_windows
url_launcher_windows