Ignore increasing brightness for non-mobile platforms

This commit is contained in:
OmarHatem 2023-01-28 17:13:34 +02:00
parent 6b2bf313a3
commit b6666ca405
2 changed files with 37 additions and 17 deletions

View file

@ -1,8 +1,9 @@
import 'dart:io';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
@ -59,12 +60,8 @@ class QRWidget extends StatelessWidget {
builder: (_) => Flexible(
flex: 5,
child: GestureDetector(
onTap: () async {
// Get the current brightness:
final double brightness = await DeviceDisplayBrightness.getBrightness();
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(1.0);
onTap: () {
changeBrightnessForRoute(() async {
await Navigator.pushNamed(
context,
Routes.fullscreenQR,
@ -73,8 +70,7 @@ class QRWidget extends StatelessWidget {
'isLight': isLight,
},
);
// ignore: unawaited_futures
DeviceDisplayBrightness.setBrightness(brightness);
});
},
child: Hero(
tag: Key(addressListViewModel.uri.toString()),
@ -173,4 +169,25 @@ class QRWidget extends StatelessWidget {
],
);
}
Future<void> changeBrightnessForRoute(Future<void> Function() navigation) async {
final isMobile = Platform.isIOS || Platform.isAndroid;
// if not mobile, just navigate
if (!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);
}
}

3
lib/utils/constants.dart Normal file
View file

@ -0,0 +1,3 @@
class ConstValues {
static const int minimumDesktopWidth = 900;
}