Add Brightness Util to check for platform before increasing brightness (#1096)

This commit is contained in:
Omar Hatem 2023-09-22 17:53:30 +03:00 committed by GitHub
parent b6de1be6c4
commit 95ea825728
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 50 deletions

View file

@ -10,7 +10,7 @@ import 'package:cake_wallet/src/screens/receive/widgets/anonpay_status_section.d
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
import 'package:cake_wallet/src/screens/receive/widgets/copy_link_item.dart'; import 'package:cake_wallet/src/screens/receive/widgets/copy_link_item.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart'; import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:device_display_brightness/device_display_brightness.dart'; import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart' as qr; import 'package:qr_flutter/qr_flutter.dart' as qr;
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart'; import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
@ -82,8 +82,7 @@ class AnonPayReceivePage extends BasePage {
@override @override
Widget Function(BuildContext, Widget) get rootWrapper => Widget Function(BuildContext, Widget) get rootWrapper =>
(BuildContext context, Widget scaffold) => (BuildContext context, Widget scaffold) => GradientBackground(scaffold: scaffold);
GradientBackground(scaffold: scaffold);
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
@ -101,19 +100,13 @@ class AnonPayReceivePage extends BasePage {
), ),
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: () async {
final double brightness = await DeviceDisplayBrightness.getBrightness(); BrightnessUtil.changeBrightnessForFunction(() async {
await Navigator.pushNamed(context, Routes.fullscreenQR,
// ignore: unawaited_futures arguments: QrViewData(
DeviceDisplayBrightness.setBrightness(1.0); data: invoiceInfo.clearnetUrl,
await Navigator.pushNamed( version: qr.QrVersions.auto,
context, ));
Routes.fullscreenQR, });
arguments: QrViewData(data: invoiceInfo.clearnetUrl,
version: qr.QrVersions.auto,
)
);
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(brightness);
}, },
child: Hero( child: Hero(
tag: Key(invoiceInfo.clearnetUrl), tag: Key(invoiceInfo.clearnetUrl),

View file

@ -3,10 +3,9 @@ import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker.dart'; import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker.dart';
import 'package:cake_wallet/src/screens/receive/widgets/currency_input_field.dart'; import 'package:cake_wallet/src/screens/receive/widgets/currency_input_field.dart';
import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
@ -64,7 +63,7 @@ class QRWidget extends StatelessWidget {
flex: 5, flex: 5,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
changeBrightnessForRoute( BrightnessUtil.changeBrightnessForFunction(
() async { () async {
await Navigator.pushNamed(context, Routes.fullscreenQR, await Navigator.pushNamed(context, Routes.fullscreenQR,
arguments: QrViewData( arguments: QrViewData(
@ -178,23 +177,4 @@ class QRWidget extends StatelessWidget {
// update amount if currency changed // update amount if currency changed
addressListViewModel.changeAmount(amountController.text); addressListViewModel.changeAmount(amountController.text);
} }
Future<void> changeBrightnessForRoute(Future<void> Function() navigation) async {
// if not mobile, just navigate
if (!DeviceInfo.instance.isMobile) {
navigation();
return;
}
// Get the current brightness:
final brightness = await DeviceDisplayBrightness.getBrightness();
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(1.0);
await navigation();
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(brightness);
}
} }

View file

@ -5,10 +5,10 @@ import 'package:cake_wallet/src/widgets/list_row.dart';
import 'package:cake_wallet/src/widgets/section_divider.dart'; import 'package:cake_wallet/src/widgets/section_divider.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:cake_wallet/utils/clipboard_util.dart'; import 'package:cake_wallet/utils/clipboard_util.dart';
import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/view_model/wallet_keys_view_model.dart'; import 'package:cake_wallet/view_model/wallet_keys_view_model.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
@ -26,19 +26,15 @@ class WalletKeysPage extends BasePage {
@override @override
Widget trailing(BuildContext context) => IconButton( Widget trailing(BuildContext context) => IconButton(
onPressed: () async { onPressed: () async {
// Get the current brightness:
final double brightness = await DeviceDisplayBrightness.getBrightness();
final url = await walletKeysViewModel.url; final url = await walletKeysViewModel.url;
// ignore: unawaited_futures BrightnessUtil.changeBrightnessForFunction(() async {
DeviceDisplayBrightness.setBrightness(1.0); await Navigator.pushNamed(
await Navigator.pushNamed( context,
context, Routes.fullscreenQR,
Routes.fullscreenQR, arguments: QrViewData(data: url.toString(), version: QrVersions.auto),
arguments: QrViewData(data: url.toString(), version: QrVersions.auto), );
); });
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(brightness);
}, },
splashColor: Colors.transparent, splashColor: Colors.transparent,
highlightColor: Colors.transparent, highlightColor: Colors.transparent,

View file

@ -0,0 +1,23 @@
import 'package:cake_wallet/utils/device_info.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
class BrightnessUtil {
static Future<void> changeBrightnessForFunction(Future<void> Function() func) async {
// if not mobile, just navigate
if (!DeviceInfo.instance.isMobile) {
func();
return;
}
// Get the current brightness:
final brightness = await DeviceDisplayBrightness.getBrightness();
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(1.0);
await func();
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(brightness);
}
}