Skip to content

Commit

Permalink
Merge pull request #358 from privacyidea/v4.3.0-fix-minor-customizati…
Browse files Browse the repository at this point in the history
…on-issues

fix minor customization issues
  • Loading branch information
frankmer authored Mar 5, 2024
2 parents 89b50f6 + 3b7652a commit a07ada1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 44 deletions.
9 changes: 8 additions & 1 deletion lib/mains/main_customizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
limitations under the License.
*/

import 'dart:developer';

import 'package:easy_dynamic_theme/easy_dynamic_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -45,14 +47,19 @@ void main() async {
}

class CustomizationAuthenticator extends ConsumerWidget {
static WidgetRef? globalAppRef;

const CustomizationAuthenticator({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
WidgetsFlutterBinding.ensureInitialized();
globalAppRef = ref;
globalRef = ref;
final state = ref.watch(settingsProvider);
final locale = state.currentLocale;
final applicationCustomizer = ref.watch(applicationCustomizerProvider);
log('applicationCustomizer primaryColor: ${applicationCustomizer.lightTheme.primaryColor}');
log('applicationCustomizer primaryColor gen: ${applicationCustomizer.generateLightTheme().primaryColor}');
return LayoutBuilder(
builder: (context, constraints) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Expand All @@ -67,7 +74,7 @@ class CustomizationAuthenticator extends ConsumerWidget {
title: applicationCustomizer.appName,
theme: applicationCustomizer.generateLightTheme(),
darkTheme: applicationCustomizer.generateDarkTheme(),
scaffoldMessengerKey: globalSnackbarKey, // <= this
scaffoldMessengerKey: globalSnackbarKey,
themeMode: EasyDynamicTheme.of(context).themeMode,
initialRoute: SplashScreen.routeName,
routes: {
Expand Down
85 changes: 45 additions & 40 deletions lib/utils/app_customizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,49 +188,54 @@ class ThemeCustomization {
);

factory ThemeCustomization.fromJson(Map<String, dynamic> json) {
bool isLightTheme = json['brightness'] == 'dark' ? false : true;
bool isLightTheme = json['brightness'] == 'light';
bool isDarkTheme = json['brightness'] == 'dark';
if (json['brightness'] == null && json['primaryColor'] != null) {
isLightTheme = _isColorBright(Color(json['primaryColor'] as int));
}
return isLightTheme
? ThemeCustomization.defaultLightWith(
primaryColor: json['primaryColor'] != null ? Color(json['primaryColor'] as int) : null,
onPrimary: json['onPrimary'] != null ? Color(json['onPrimary'] as int) : null,
subtitleColor: json['subtitleColor'] != null ? Color(json['subtitleColor'] as int) : null,
backgroundColor: json['backgroundColor'] != null ? Color(json['backgroundColor'] as int) : null,
foregroundColor: json['foregroundColor'] != null ? Color(json['foregroundColor'] as int) : null,
shadowColor: json['shadowColor'] != null ? Color(json['shadowColor'] as int) : null,
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
actionButtonsForegroundColor: json['actionButtonsForegroundColor'] != null ? Color(json['actionButtonsForegroundColor'] as int) : null,
tilePrimaryColor: json['tilePrimaryColor'] != null ? Color(json['tilePrimaryColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
tileSubtitleColor: json['tileSubtitleColor'] != null ? Color(json['tileSubtitleColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
navigationBarIconColor: json['navigationBarIconColor'] != null ? Color(json['navigationBarIconColor'] as int) : null,
qrButtonBackgroundColor: json['qrButtonBackgroundColor'] != null ? Color(json['qrButtonBackgroundColor'] as int) : null,
qrButtonIconColor: json['qrButtonIconColor'] != null ? Color(json['qrButtonIconColor'] as int) : null,
)
: ThemeCustomization.defaultDarkWith(
primaryColor: json['primaryColor'] != null ? Color(json['primaryColor'] as int) : null,
onPrimary: json['onPrimary'] != null ? Color(json['onPrimary'] as int) : null,
subtitleColor: json['subtitleColor'] != null ? Color(json['subtitleColor'] as int) : null,
backgroundColor: json['backgroundColor'] != null ? Color(json['backgroundColor'] as int) : null,
foregroundColor: json['foregroundColor'] != null ? Color(json['foregroundColor'] as int) : null,
shadowColor: json['shadowColor'] != null ? Color(json['shadowColor'] as int) : null,
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
actionButtonsForegroundColor: json['actionButtonsForegroundColor'] != null ? Color(json['actionButtonsForegroundColor'] as int) : null,
tilePrimaryColor: json['tilePrimaryColor'] != null ? Color(json['tilePrimaryColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
tileSubtitleColor: json['tileSubtitleColor'] != null ? Color(json['tileSubtitleColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
navigationBarIconColor: json['navigationBarIconColor'] != null ? Color(json['navigationBarIconColor'] as int) : null,
qrButtonBackgroundColor: json['qrButtonBackgroundColor'] != null ? Color(json['qrButtonBackgroundColor'] as int) : null,
qrButtonIconColor: json['qrButtonIconColor'] != null ? Color(json['qrButtonIconColor'] as int) : null,
);
if (isLightTheme) {
return ThemeCustomization.defaultLightWith(
primaryColor: json['primaryColor'] != null ? Color(json['primaryColor'] as int) : null,
onPrimary: json['onPrimary'] != null ? Color(json['onPrimary'] as int) : null,
subtitleColor: json['subtitleColor'] != null ? Color(json['subtitleColor'] as int) : null,
backgroundColor: json['backgroundColor'] != null ? Color(json['backgroundColor'] as int) : null,
foregroundColor: json['foregroundColor'] != null ? Color(json['foregroundColor'] as int) : null,
shadowColor: json['shadowColor'] != null ? Color(json['shadowColor'] as int) : null,
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
actionButtonsForegroundColor: json['actionButtonsForegroundColor'] != null ? Color(json['actionButtonsForegroundColor'] as int) : null,
tilePrimaryColor: json['tilePrimaryColor'] != null ? Color(json['tilePrimaryColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
tileSubtitleColor: json['tileSubtitleColor'] != null ? Color(json['tileSubtitleColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
navigationBarIconColor: json['navigationBarIconColor'] != null ? Color(json['navigationBarIconColor'] as int) : null,
qrButtonBackgroundColor: json['qrButtonBackgroundColor'] != null ? Color(json['qrButtonBackgroundColor'] as int) : null,
qrButtonIconColor: json['qrButtonIconColor'] != null ? Color(json['qrButtonIconColor'] as int) : null,
);
}
if (isDarkTheme) {
return ThemeCustomization.defaultDarkWith(
primaryColor: json['primaryColor'] != null ? Color(json['primaryColor'] as int) : null,
onPrimary: json['onPrimary'] != null ? Color(json['onPrimary'] as int) : null,
subtitleColor: json['subtitleColor'] != null ? Color(json['subtitleColor'] as int) : null,
backgroundColor: json['backgroundColor'] != null ? Color(json['backgroundColor'] as int) : null,
foregroundColor: json['foregroundColor'] != null ? Color(json['foregroundColor'] as int) : null,
shadowColor: json['shadowColor'] != null ? Color(json['shadowColor'] as int) : null,
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
actionButtonsForegroundColor: json['actionButtonsForegroundColor'] != null ? Color(json['actionButtonsForegroundColor'] as int) : null,
tilePrimaryColor: json['tilePrimaryColor'] != null ? Color(json['tilePrimaryColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
tileSubtitleColor: json['tileSubtitleColor'] != null ? Color(json['tileSubtitleColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
navigationBarIconColor: json['navigationBarIconColor'] != null ? Color(json['navigationBarIconColor'] as int) : null,
qrButtonBackgroundColor: json['qrButtonBackgroundColor'] != null ? Color(json['qrButtonBackgroundColor'] as int) : null,
qrButtonIconColor: json['qrButtonIconColor'] != null ? Color(json['qrButtonIconColor'] as int) : null,
);
}
throw Exception('Invalid brightness value: ${json['brightness']}');
}

Map<String, dynamic> toJson() => <String, dynamic>{
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/app_info_utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'version.dart';

Expand All @@ -14,8 +15,8 @@ class AppInfoUtils {
_packageName = (await packageInfo).packageName;
_appVersion = Version.parse((await packageInfo).version);
_appBuildNumber = (await packageInfo).buildNumber;
_androidInfo = Platform.isAndroid ? await _deviceInfo.androidInfo : null;
_iosInfo = Platform.isIOS ? await _deviceInfo.iosInfo : null;
_androidInfo = !kIsWeb && Platform.isAndroid ? await _deviceInfo.androidInfo : null;
_iosInfo = !kIsWeb && Platform.isIOS ? await _deviceInfo.iosInfo : null;

isInitialized = true;
}
Expand All @@ -39,6 +40,7 @@ class AppInfoUtils {
static String get platform => Platform.operatingSystem;

static String get deviceInfoString {
if (kIsWeb) return 'Web: Not available.';
if (Platform.isAndroid) {
return 'Android:\n$_androidDeviceInfoString';
} else if (Platform.isIOS) {
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/home_widget_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:home_widget/home_widget.dart';
import 'package:mutex/mutex.dart';
Expand Down Expand Up @@ -137,6 +138,17 @@ class HomeWidgetUtils {
Stream<Uri?> get widgetClicked => HomeWidget.widgetClicked;
Future<Uri?> initiallyLaunchedFromHomeWidget() => HomeWidget.initiallyLaunchedFromHomeWidget();

static bool? _isHomeWidgetSupported;
static Future<bool> get isHomeWidgetSupported async {
if (_isHomeWidgetSupported != null) return _isHomeWidgetSupported!;
if (kIsWeb || Platform.isIOS) {
_isHomeWidgetSupported = false;
return _isHomeWidgetSupported!;
}
_isHomeWidgetSupported = true;
return _isHomeWidgetSupported!;
}

Future<List<String>> get _widgetIds async => (await HomeWidget.getWidgetData<String?>(keyWidgetIds))?.split(',') ?? <String>[];

// _packageId must be the exact id of the package variable in "AndroidManifest.xml" !! NOT the applicationId of the flavor !!
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/patch_notes_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class PatchNotesUtils {
static void _showPatchNotes({required BuildContext context, required Version latestStartedVersion}) {
final newNotes = _getNewPatchNotes(context: context, latestStartedVersion: latestStartedVersion);
if (newNotes.isEmpty) return;
showDialog(context: context, builder: (context) => PatchNotesDialog(newNotes: newNotes), barrierDismissible: false);
showDialog(
context: context,
builder: (context) => PatchNotesDialog(newNotes: newNotes),
barrierDismissible: false,
useRootNavigator: false,
);
}
}

0 comments on commit a07ada1

Please sign in to comment.