Skip to content

Commit

Permalink
refactor: Common method to get the current app brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
enrique-lozano committed May 1, 2024
1 parent eeed4d4 commit 17fa95f
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 38 deletions.
2 changes: 0 additions & 2 deletions lib/app/accounts/account_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ class _AccountFormPageState extends State<AccountFormPage> {
return const LinearProgressIndicator();
}

final isDark = Theme.of(context).brightness == Brightness.dark;

return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Form(
Expand Down
5 changes: 3 additions & 2 deletions lib/app/accounts/account_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:monekin/core/database/app_db.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/models/account/account.dart';
import 'package:monekin/core/models/supported-icon/icon_displayer.dart';
import 'package:monekin/core/presentation/app_colors.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/bottomSheetFooter.dart';
import 'package:monekin/core/presentation/widgets/modal_container.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/widgets/icon_displayer_widgets.dart';
Expand Down Expand Up @@ -237,7 +238,7 @@ class _AccountSelectorState extends State<AccountSelector> {
padding: widget.params.iconPadding,
isOutline: selectedAccounts == null,
secondaryColor: AppColors.of(context).background.darken(
Theme.of(context).brightness == Brightness.dark ? 0.6 : 0.1,
isAppInDarkBrightness(context) ? 0.6 : 0.1,
),
mainColor: AppColors.of(context).onBackground,
onTap: () {
Expand Down
12 changes: 5 additions & 7 deletions lib/app/categories/categories_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import 'package:monekin/app/categories/category_selector.dart';
import 'package:monekin/app/categories/form/category_form.dart';
import 'package:monekin/app/categories/subcategory_selector.dart';
import 'package:monekin/core/database/services/category/category_service.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/models/category/category.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/icon_displayer_widgets.dart';
import 'package:monekin/core/presentation/widgets/persistent_footer_button.dart';
import 'package:monekin/core/routes/route_utils.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/app_colors.dart';
Expand Down Expand Up @@ -231,18 +232,15 @@ class _CategoriesListState extends State<CategoriesList> {
),
TabBar(
labelColor:
Theme.of(context).brightness == Brightness.light &&
widget.mode.isModal
isAppInLightBrightness(context) && widget.mode.isModal
? AppColors.of(context).primary
: null,
unselectedLabelColor:
Theme.of(context).brightness == Brightness.light &&
widget.mode.isModal
isAppInLightBrightness(context) && widget.mode.isModal
? AppColors.of(context).onBackground.lighten(0.3)
: null,
indicatorColor:
Theme.of(context).brightness == Brightness.light &&
widget.mode.isModal
isAppInLightBrightness(context) && widget.mode.isModal
? AppColors.of(context).primary
: null,
tabs: [
Expand Down
3 changes: 2 additions & 1 deletion lib/app/categories/category_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/models/category/category.dart';
import 'package:monekin/core/models/supported-icon/icon_displayer.dart';
import 'package:monekin/core/presentation/app_colors.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/widgets/icon_displayer_widgets.dart';
Expand Down Expand Up @@ -94,7 +95,7 @@ class _CategorySelectorState extends State<CategorySelector> {
borderRadius: 99999,
isOutline: selectedCategories == null,
secondaryColor: AppColors.of(context).background.darken(
Theme.of(context).brightness == Brightness.dark ? 0.6 : 0.1,
isAppInDarkBrightness(context) ? 0.6 : 0.1,
),
mainColor: AppColors.of(context).onBackground,
onTap: () {
Expand Down
3 changes: 2 additions & 1 deletion lib/app/settings/purchases/donate_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:monekin/app/settings/purchases/in_app_purchase.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../../core/presentation/app_colors.dart';
Expand Down Expand Up @@ -130,7 +131,7 @@ class _DonateButtonState extends State<DonateButton> {
child: Card(
clipBehavior: Clip.hardEdge,
margin: const EdgeInsets.all(0),
color: Theme.of(context).brightness == Brightness.light
color: isAppInLightBrightness(context)
? AppColors.of(context).danger.lighten(0.8)
: AppColors.of(context).danger.withOpacity(0.2),
shape: RoundedRectangleBorder(
Expand Down
5 changes: 3 additions & 2 deletions lib/app/settings/widgets/setting_card_item.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/presentation/app_colors.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/tappable.dart';
import 'package:monekin/core/extensions/color.extensions.dart';

class SettingCardItem extends StatelessWidget {
const SettingCardItem({
Expand All @@ -25,7 +26,7 @@ class SettingCardItem extends StatelessWidget {
Widget build(BuildContext context) {
return Tappable(
bgColor: isPrimary
? Theme.of(context).brightness == Brightness.light
? isAppInLightBrightness(context)
? AppColors.of(context).primary.lighten(0.8)
: AppColors.of(context).primary.darken(0.8)
: null,
Expand Down
15 changes: 7 additions & 8 deletions lib/app/stats/widgets/balance_bar_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:monekin/core/models/date-utils/date_period.dart';
import 'package:monekin/core/models/date-utils/date_period_state.dart';
import 'package:monekin/core/models/date-utils/period_type.dart';
import 'package:monekin/core/models/date-utils/periodicity.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/ui_number_formatter.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';

Expand Down Expand Up @@ -286,15 +287,13 @@ class _BalanceBarChartState extends State<BalanceBarChart> {
);
}

final ultraLightBorderColor =
Theme.of(context).brightness == Brightness.light
? Colors.black12
: Colors.white12;
final ultraLightBorderColor = isAppInLightBrightness(context)
? Colors.black12
: Colors.white12;

final lightBorderColor =
Theme.of(context).brightness == Brightness.light
? Colors.black26
: Colors.white24;
final lightBorderColor = isAppInLightBrightness(context)
? Colors.black26
: Colors.white24;

return BarChart(BarChartData(
barTouchData: BarTouchData(
Expand Down
8 changes: 4 additions & 4 deletions lib/app/stats/widgets/balance_bar_chart_small.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/models/date-utils/date_period_state.dart';
import 'package:monekin/core/presentation/responsive/breakpoints.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';
import 'package:monekin/i18n/translations.g.dart';

Expand Down Expand Up @@ -119,10 +120,9 @@ class _BalanceChartSmallState extends State<BalanceChartSmall> {

final accounts = accountsSnapshot.data!;

final ultraLightBorderColor =
Theme.of(context).brightness == Brightness.light
? Colors.black12
: Colors.white12;
final ultraLightBorderColor = isAppInLightBrightness(context)
? Colors.black12
: Colors.white12;

if (accounts.isEmpty) {
return Stack(
Expand Down
10 changes: 5 additions & 5 deletions lib/app/stats/widgets/fund_evolution_line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/database/services/currency/currency_service.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/models/date-utils/date_period_state.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/ui_number_formatter.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';
import 'package:monekin/core/presentation/widgets/trending_value.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/utils/constants.dart';
import 'package:monekin/i18n/translations.g.dart';
import 'package:rxdart/rxdart.dart';
Expand Down Expand Up @@ -190,10 +191,9 @@ class FundEvolutionLineChart extends StatelessWidget {
);
}

final ultraLightBorderColor =
Theme.of(context).brightness == Brightness.light
? Colors.black12
: Colors.white12;
final ultraLightBorderColor = isAppInLightBrightness(context)
? Colors.black12
: Colors.white12;

return StreamBuilder(
stream: CurrencyService.instance.getUserPreferredCurrency(),
Expand Down
4 changes: 2 additions & 2 deletions lib/app/transactions/transaction_details.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:monekin/core/models/supported-icon/supported_icon.dart';
import 'package:monekin/core/models/tags/tag.dart';
import 'package:monekin/core/models/transaction/transaction.dart';
import 'package:monekin/core/models/transaction/transaction_status.enum.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/card_with_header.dart';
import 'package:monekin/core/presentation/widgets/confirm_dialog.dart';
import 'package:monekin/core/presentation/widgets/monekin_quick_actions_buttons.dart';
Expand Down Expand Up @@ -529,8 +530,7 @@ class _TransactionDetailsPageState extends State<TransactionDetailsPage> {
color: ColorHex.get(
transaction.category!.color)
.lighten(
Theme.of(context).brightness ==
Brightness.dark
isAppInDarkBrightness(context)
? 0.5
: 0),
data: transaction.category!.name,
Expand Down
3 changes: 2 additions & 1 deletion lib/core/models/account/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/models/supported-icon/icon_displayer.dart';
import 'package:monekin/core/models/supported-icon/supported_icon.dart';
import 'package:monekin/core/presentation/app_colors.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/services/supported_icon/supported_icon_service.dart';
import 'package:monekin/i18n/translations.g.dart';

Expand Down Expand Up @@ -90,7 +91,7 @@ class Account extends AccountInDB {
bool isOutline = false,
void Function()? onTap,
}) {
bool isDark = Theme.of(context).brightness == Brightness.dark;
bool isDark = isAppInDarkBrightness(context);

return IconDisplayer(
supportedIcon: icon,
Expand Down
5 changes: 5 additions & 0 deletions lib/core/presentation/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import 'app_colors.dart';

bool isAppUsingDynamicColors = false;

bool isAppInDarkBrightness(BuildContext context) =>
Theme.of(context).brightness == Brightness.dark;
bool isAppInLightBrightness(BuildContext context) =>
!isAppInDarkBrightness(context);

ThemeData getThemeData(
BuildContext context, {
required bool isDark,
Expand Down
3 changes: 2 additions & 1 deletion lib/core/presentation/widgets/no_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:monekin/core/presentation/animations/shake/fade_in.dart';
import 'package:monekin/core/presentation/app_colors.dart';
import 'package:monekin/core/presentation/theme.dart';

class NoResults extends StatelessWidget {
const NoResults({
Expand All @@ -23,7 +24,7 @@ class NoResults extends StatelessWidget {
Widget build(BuildContext context) {
return FadeIn(
child: Opacity(
opacity: Theme.of(context).brightness == Brightness.light ? 1 : 0.8,
opacity: isAppInLightBrightness(context) ? 1 : 0.9,
child: Center(
child: Padding(
padding: padding ??
Expand Down
4 changes: 2 additions & 2 deletions lib/core/presentation/widgets/trending_value.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/ui_number_formatter.dart';

import '../app_colors.dart';
Expand Down Expand Up @@ -61,8 +62,7 @@ class TrendingValue extends StatelessWidget {
return percentage == 0
? AppColors.of(context)
.brand
.lighten(
Theme.of(context).brightness == Brightness.dark ? 0.45 : 0.25)
.lighten(isAppInDarkBrightness(context) ? 0.45 : 0.25)
.withBlue(225)
: percentage > 0
? AppColors.of(context).success
Expand Down

0 comments on commit 17fa95f

Please sign in to comment.