Skip to content

Commit

Permalink
[Presentation] Manually implemented the dark amoled theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 6, 2022
1 parent 208a290 commit c6348ed
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 23 deletions.
4 changes: 1 addition & 3 deletions lib/application/main/main_bloc.dart
Expand Up @@ -95,9 +95,7 @@ class MainBloc extends Bloc<MainEvent, MainState> {
'_init: Is first install = ${_settingsService.isFirstInstall} ' + '-- versionChanged = ${_deviceInfoService.versionChanged}',
);

final features = await _purchaseService.getUnlockedFeatures();
final useDarkAmoledTheme = true && features.contains(AppUnlockedFeature.darkAmoledTheme);

final useDarkAmoledTheme = _settingsService.useDarkAmoledTheme && await _purchaseService.isFeatureUnlocked(AppUnlockedFeature.darkAmoledTheme);
return MainState.loaded(
appTitle: _deviceInfoService.appName,
accentColor: accentColor,
Expand Down
2 changes: 2 additions & 0 deletions lib/domain/services/purchase_service.dart
Expand Up @@ -19,4 +19,6 @@ abstract class PurchaseService {
Future<bool> restorePurchases(String userId, {String? entitlementIdentifier});

Future<List<AppUnlockedFeature>> getUnlockedFeatures();

Future<bool> isFeatureUnlocked(AppUnlockedFeature feature);
}
4 changes: 2 additions & 2 deletions lib/presentation/donations/donations_bottom_sheet.dart
Expand Up @@ -144,9 +144,9 @@ class _BodyState extends State<_Body> {
final toast = ToastUtils.of(context);
String msg = '';
if (isPurchase) {
msg = error ? s.paymentError : s.paymentSucceed;
msg = error ? s.paymentError : '${s.paymentSucceed}\n${s.restartMayBeNeeded}';
} else {
msg = error ? s.restorePurchaseError : s.restorePurchaseSucceed;
msg = error ? s.restorePurchaseError : '${s.restorePurchaseSucceed}\n${s.restartMayBeNeeded}';
}

if (!error) {
Expand Down
15 changes: 13 additions & 2 deletions lib/presentation/settings/widgets/theme_settings_card.dart
@@ -1,3 +1,6 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shiori/application/bloc.dart';
Expand All @@ -18,6 +21,7 @@ class ThemeSettingsCard extends StatelessWidget {
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
final darkAmoledThemeIsSupported = !kIsWeb && (Platform.isAndroid || Platform.isIOS);
return SettingsCard(
child: BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, state) => state.maybeMap(
Expand Down Expand Up @@ -52,12 +56,19 @@ class ThemeSettingsCard extends StatelessWidget {
onChanged: _appThemeChanged,
),
),
if (state.currentTheme == AppThemeType.dark)
if (darkAmoledThemeIsSupported && state.currentTheme == AppThemeType.dark)
SwitchListTile(
activeColor: theme.colorScheme.secondary,
title: Text(s.useDarkAmoledTheme),
value: state.useDarkAmoledTheme,
onChanged: (newVal) => context.read<SettingsBloc>().add(SettingsEvent.useDarkAmoledTheme(newValue: newVal)),
subtitle: state.unlockedFeatures.contains(AppUnlockedFeature.darkAmoledTheme) ? null : Text(
s.unlockedWithDonation,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.caption!.copyWith(color: theme.primaryColor, fontStyle: FontStyle.italic),
),
onChanged: !state.unlockedFeatures.contains(AppUnlockedFeature.darkAmoledTheme)
? null
: (newVal) => context.read<SettingsBloc>().add(SettingsEvent.useDarkAmoledTheme(newValue: newVal)),
),
],
),
Expand Down
Expand Up @@ -208,6 +208,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
onHorizontalDragEnd: handleDragEnd,
child: SafeArea(
child: Material(
color: widget.backgroundColor,
child: Container(
margin: const EdgeInsets.only(top: 10, left: 16, right: 16),
child: widget.route!.builder!(context),
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/shared/common_dropdown_button.dart
Expand Up @@ -23,6 +23,7 @@ class CommonDropdownButton<T> extends StatelessWidget {
Widget build(BuildContext context) {
return DropdownButton<T>(
isExpanded: isExpanded,
dropdownColor: Theme.of(context).cardColor,
hint: Text(hint),
value: currentValue,
underline: withoutUnderLine
Expand Down
Expand Up @@ -71,7 +71,9 @@ class _TwoColumnEnumSelectorDialogState<TEnum> extends State<TwoColumnEnumSelect
}
final dialogHeight = mq.getHeightForDialogs(_all.length + _selected.length, maxHeight: 400);
final dialogWidth = mq.getWidthForDialogs();
final bgColor = theme.brightness == Brightness.dark ? theme.backgroundColor.withOpacity(0.8) : theme.dividerColor;
final bgColor = theme.brightness == Brightness.dark
? (theme.scaffoldBackgroundColor == Colors.black ? theme.cardColor : theme.backgroundColor.withOpacity(0.8))
: theme.dividerColor;
final canAddMoreItems = _selected.length == widget.maxNumberOfSelections;
return AlertDialog(
title: useRow
Expand Down
35 changes: 29 additions & 6 deletions lib/presentation/shared/extensions/app_theme_type_extensions.dart
@@ -1,4 +1,3 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import 'package:shiori/domain/enums/enums.dart';

Expand Down Expand Up @@ -42,14 +41,38 @@ extension AppThemeTypeExtensions on AppAccentColorType {

ThemeData getThemeData(AppThemeType theme, bool useDarkAmoledTheme) {
final color = getAccentColor();
final colors = FlexSchemeColor.from(primary: color, secondary: color, primaryVariant: color, secondaryVariant: color);
switch (theme) {
case AppThemeType.dark:
return FlexThemeData.dark(colors: colors, darkIsTrueBlack: useDarkAmoledTheme);
final colorScheme = ColorScheme.dark(primary: color, secondary: color, primaryVariant: color, secondaryVariant: color);
final dark = ThemeData.dark().copyWith(
primaryColor: color,
primaryColorLight: color.withOpacity(0.5),
primaryColorDark: color,
useMaterial3: true,
colorScheme: colorScheme,
);

if (!useDarkAmoledTheme) {
return dark;
}

const almostBlackColor = Color.fromARGB(255, 16, 16, 16);
return dark.copyWith(
scaffoldBackgroundColor: Colors.black,
popupMenuTheme: const PopupMenuThemeData(color: almostBlackColor),
bottomSheetTheme: const BottomSheetThemeData(backgroundColor: almostBlackColor),
bottomNavigationBarTheme: const BottomNavigationBarThemeData(backgroundColor: almostBlackColor),
cardColor: almostBlackColor,
dialogBackgroundColor: almostBlackColor,
colorScheme: colorScheme.copyWith(surface: almostBlackColor),
);
case AppThemeType.light:
return FlexThemeData.light(
colors: colors,
appBarElevation: 10,
return ThemeData.light().copyWith(
primaryColor: color,
primaryColorLight: color.withOpacity(0.8),
primaryColorDark: color,
useMaterial3: true,
colorScheme: ColorScheme.light(primary: color, secondary: color),
);
default:
throw Exception('The provided theme = $theme is not valid ');
Expand Down
3 changes: 2 additions & 1 deletion lib/presentation/shared/utils/modal_bottom_sheet_utils.dart
Expand Up @@ -32,8 +32,9 @@ class ModalBottomSheetUtils {
case EndDrawerItemType.notifications:
assert(args != null);
return notifications.AddEditNotificationBottomSheet.getWidgetFromArgs(context, args!);
default:
throw Exception('Type = $type is not mapped');
}
return Container();
}

static Future<void> showAppModalBottomSheet(BuildContext context, EndDrawerItemType type, {Map<String, dynamic>? args}) async {
Expand Down
7 changes: 0 additions & 7 deletions pubspec.lock
Expand Up @@ -316,13 +316,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flex_color_scheme:
dependency: "direct main"
description:
name: flex_color_scheme
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Expand Up @@ -25,7 +25,6 @@ dependencies:
device_info_plus: ^3.2.0
devicelocale: ^0.5.0
enum_to_string: ^2.0.1
flex_color_scheme: ^4.2.0
flutter:
sdk: flutter
flutter_bloc: ^7.3.1
Expand Down

0 comments on commit c6348ed

Please sign in to comment.