From c2da8e36da55c475872fc2acdf2c0f6f69e1ee67 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Thu, 8 Sep 2022 12:09:12 +0100 Subject: [PATCH] fix: only show Material You toggle for SDK version >= 31 --- .vscode/tasks.json | 6 ---- lib/ui/views/settings/settings_view.dart | 36 +++++++++++-------- lib/ui/views/settings/settings_viewmodel.dart | 9 +++++ pubspec.yaml | 4 +-- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0fa4713f..a09c28f5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -81,12 +81,6 @@ ], "problemMatcher": [] }, - { - "label": "Show upgradable dependencies", - "type": "shell", - "command": "flutter pub outdated", - "problemMatcher": [] - }, { "label": "Validate translations", "type": "shell", diff --git a/lib/ui/views/settings/settings_view.dart b/lib/ui/views/settings/settings_view.dart index ca48808f..f4a4dd18 100644 --- a/lib/ui/views/settings/settings_view.dart +++ b/lib/ui/views/settings/settings_view.dart @@ -60,23 +60,31 @@ class SettingsView extends StatelessWidget { value, ), ), - CustomSwitchTile( - title: I18nText( - 'settingsView.dynamicThemeLabel', - child: const Text( - '', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w500, + FutureBuilder( + future: model.getSdkVersion(), + builder: (context, snapshot) => Visibility( + visible: snapshot.hasData && + snapshot.data! >= ANDROID_12_SDK_VERSION, + child: CustomSwitchTile( + title: I18nText( + 'settingsView.dynamicThemeLabel', + child: const Text( + '', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ), + subtitle: + I18nText('settingsView.dynamicThemeHint'), + value: model.getDynamicThemeStatus(), + onTap: (value) => model.setUseDynamicTheme( + context, + value, ), ), ), - subtitle: I18nText('settingsView.dynamicThemeHint'), - value: model.getDynamicThemeStatus(), - onTap: (value) => model.setUseDynamicTheme( - context, - value, - ), ), ], ), diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index ca041e9b..454df33b 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -1,5 +1,6 @@ // ignore_for_file: use_build_context_synchronously +import 'package:device_info_plus/device_info_plus.dart'; import 'package:dynamic_themes/dynamic_themes.dart'; import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; @@ -12,6 +13,9 @@ import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; import 'package:timeago/timeago.dart'; +// ignore: constant_identifier_names +const int ANDROID_12_SDK_VERSION = 31; + class SettingsViewModel extends BaseViewModel { final NavigationService _navigationService = locator(); final ManagerAPI _managerAPI = locator(); @@ -212,4 +216,9 @@ class SettingsViewModel extends BaseViewModel { ), ); } + + Future getSdkVersion() async { + AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo; + return info.version.sdkInt ?? -1; + } } diff --git a/pubspec.yaml b/pubspec.yaml index da6a7263..2dc97fc4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,8 +44,8 @@ dependencies: share_extend: ^2.0.0 shared_preferences: ^2.0.15 skeletons: ^0.0.3 - stacked: ^2.3.15 - stacked_generator: ^0.7.14 + stacked: ^3.0.0 + stacked_generator: ^0.8.0 stacked_services: ^0.9.3 stacked_themes: ^0.3.9 timeago: ^3.2.2