Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:enrique-lozano/Monekin into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
enrique-lozano committed Jan 9, 2025
2 parents 9499a2b + 580ddb3 commit 06e447f
Show file tree
Hide file tree
Showing 21 changed files with 637 additions and 123 deletions.
11 changes: 8 additions & 3 deletions lib/app/accounts/account_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:monekin/core/models/account/account.dart';
import 'package:monekin/core/models/currency/currency.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/theme.dart';
import 'package:monekin/core/presentation/widgets/color_picker/color_picker.dart';
import 'package:monekin/core/presentation/widgets/currency_selector_modal.dart';
import 'package:monekin/core/presentation/widgets/expansion_panel/single_expansion_panel.dart';
Expand Down Expand Up @@ -98,7 +99,7 @@ class _AccountFormPageState extends State<AccountFormPage> {
closingDate: _closeDate,
type: _type,
iconId: _icon.id,
color: _color.toHex(leadingHashSign: false),
color: _color.toHex(),
currency: _currency!,
iban: _ibanController.text.isEmpty ? null : _ibanController.text,
description: _textController.text.isEmpty ? null : _textController.text,
Expand Down Expand Up @@ -233,6 +234,8 @@ class _AccountFormPageState extends State<AccountFormPage> {
return const LinearProgressIndicator();
}

final isDark = isAppInDarkBrightness(context);

return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Form(
Expand All @@ -248,8 +251,10 @@ class _AccountFormPageState extends State<AccountFormPage> {
size: 36,
isOutline: true,
outlineWidth: 1.5,
mainColor: _color.lighten(IconDisplayer.darkLightenFactor),
secondaryColor: _color,
mainColor: _color
.lighten(isDark ? IconDisplayer.darkLightenFactor : 0),
secondaryColor: _color
.lighten(isDark ? 0 : IconDisplayer.darkLightenFactor),
displayMode: IconDisplayMode.polygon,
),
onDataChange: ((data) {
Expand Down
20 changes: 15 additions & 5 deletions lib/app/categories/form/icon_and_color_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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/presentation/widgets/color_picker/color_picker.dart';
import 'package:monekin/core/presentation/widgets/color_picker/color_picker_modal.dart';
import 'package:monekin/core/presentation/widgets/icon_selector_modal.dart';
Expand Down Expand Up @@ -75,12 +76,21 @@ class IconAndColorSelector extends StatelessWidget {
ColorPickerModal(
colorOptions: defaultColorPickerOptions,
selectedColor: data.color.toHex(),
customColorPreviewBuilder: (color) =>
iconDisplayer.copyWith(
secondaryColor:
isAppInDarkBrightness(context) ? color : null,
mainColor:
isAppInLightBrightness(context) ? color : null,
size: 32,
outlineWidth: 2,
),
onColorSelected: (selColor) {
Navigator.pop(context);
onDataChange((color: selColor, icon: data.icon));
},
),
).then((selColor) {
if (selColor == null) return;

onDataChange((color: selColor, icon: data.icon));
}),
),
bgColor: Theme.of(context).colorSchemeExtended.inputFill,
child: ListTile(
mouseCursor: SystemMouseCursors.click,
Expand Down
27 changes: 14 additions & 13 deletions lib/app/settings/appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class _AdvancedSettingsPageState extends State<AdvancedSettingsPage> {
onSwitch: (bool value) async {
await UserSettingService.instance.setItem(
SettingKey.accentColor,
value ? 'auto' : brandBlue.toHex(leadingHashSign: false),
value ? 'auto' : brandBlue.toHex(),
updateGlobalState: true,
);
},
Expand All @@ -224,22 +224,23 @@ class _AdvancedSettingsPageState extends State<AdvancedSettingsPage> {
context,
ColorPickerModal(
colorOptions: [
brandBlue.toHex(leadingHashSign: false),
brandBlue.toHex(),
...defaultColorPickerOptions
],
selectedColor: color.toHex(),
),
).then((value) {
if (value == null) return;
onColorSelected: (value) {
Navigator.pop(context);

setState(() {
UserSettingService.instance.setItem(
SettingKey.accentColor,
value.toHex(),
updateGlobalState: true,
);
});
}),
setState(() {
UserSettingService.instance.setItem(
SettingKey.accentColor,
value.toHex(),
updateGlobalState: true,
);
});
},
),
),
title: Text(t.settings.accent_color),
subtitle: Text(t.settings.accent_color_descr),
enabled: snapshot.data! != 'auto',
Expand Down
38 changes: 19 additions & 19 deletions lib/app/tags/tag_form_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,26 @@ class _TagFormPageState extends State<TagFormPage> {
),
const SizedBox(height: 16),
ReadOnlyTextFormField(
displayValue: null,
decoration: InputDecoration(
hintText: t.icon_selector.color,
suffixIcon: const Icon(Icons.circle),
suffixIconColor: ColorHex.get(_color),
),
onTap: () => showColorPickerModal(
context,
ColorPickerModal(
colorOptions: defaultColorPickerOptions,
selectedColor: _color,
displayValue: null,
decoration: InputDecoration(
hintText: t.icon_selector.color,
suffixIcon: const Icon(Icons.circle),
suffixIconColor: ColorHex.get(_color),
),
).then((value) {
if (value == null) return;

setState(() {
_color = value.toHex();
});
}),
),
onTap: () => showColorPickerModal(
context,
ColorPickerModal(
colorOptions: defaultColorPickerOptions,
selectedColor: _color,
onColorSelected: (value) {
Navigator.pop(context);

setState(() {
_color = value.toHex();
});
},
),
)),
const SizedBox(height: 12),
TextFormField(
controller: _descrController,
Expand Down
34 changes: 25 additions & 9 deletions lib/core/extensions/color.extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@ import 'package:flutter/material.dart';

extension ColorHex on Color {
/// Return a color instance from an hex string
static Color get(String hex) =>
Color(int.parse("0xff${hex.replaceAll('#', '')}"));

String toHex({bool leadingHashSign = true}) {
return '${leadingHashSign ? '#' : ''}'
'${alpha.toRadixString(16).padLeft(2, '0')}'
'${red.toRadixString(16).padLeft(2, '0')}'
'${green.toRadixString(16).padLeft(2, '0')}'
'${blue.toRadixString(16).padLeft(2, '0')}';
static Color get(String hex) {
hex = hex.toUpperCase().replaceAll('#', '');

if (hex.length == 6) {
hex = 'FF$hex';
}

// Parser will return errors on invalid strings, so we don't need error catching here
return Color(int.parse(hex, radix: 16));
}

String toHex({
bool leadingHashSign = false,
bool enableAlpha = false,
bool toUpperCase = true,
}) {
final String hex = (leadingHashSign ? '#' : '') +
(enableAlpha ? _padRadix(alpha) : '') +
_padRadix(red) +
_padRadix(green) +
_padRadix(blue);
return toUpperCase ? hex.toUpperCase() : hex;
}

// Shorthand for padLeft of RadixString, DRY.
String _padRadix(int value) => value.toRadixString(16).padLeft(2, '0');
}

extension ColorBrightness on Color {
Expand Down
21 changes: 15 additions & 6 deletions lib/core/models/supported-icon/supported_icon.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:monekin/core/presentation/widgets/simple_shadow.dart';

part 'supported_icon.g.dart';

Expand Down Expand Up @@ -28,12 +31,18 @@ class SupportedIcon {
return SizedBox(
height: size,
width: size,
child: SvgPicture.asset(
urlToAssets,
height: size,
width: size,
colorFilter:
color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
child: SimpleShadow(
opacity: 0.55,
sigma: min(size / 50, 0.6),
offset: const Offset(0, 0),
color: Colors.black,
child: SvgPicture.asset(
urlToAssets,
height: size,
width: size,
colorFilter:
color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
),
),
);
}
Expand Down
Loading

0 comments on commit 06e447f

Please sign in to comment.