Skip to content

Commit

Permalink
Merge pull request #79 from netglade/fix/debug-colors
Browse files Browse the repository at this point in the history
Fix colors in debug widget
  • Loading branch information
petrnymsa authored Jan 25, 2025
2 parents 87d5092 + 80dd656 commit 4f138c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions glade_forms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.1.1
- Add typedefs `IntInput` and `BooleanInput`
- Fix GladeModelDebugInfo colors in DarkMode.

## 3.1.0
- updated dependencies

Expand Down
8 changes: 5 additions & 3 deletions glade_forms/lib/src/core/glade_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ typedef OnDependencyChange = void Function(List<String> updateInputKeys);
typedef ValueTransform<T> = T Function(T input);

typedef StringInput = GladeInput<String>;
typedef StringInputNullable = GladeInput<String?>;
typedef IntInput = GladeInput<int>;
typedef BooleanInput = GladeInput<bool>;

class GladeInput<T> {
/// Compares initial and current value.
Expand Down Expand Up @@ -329,7 +331,7 @@ class GladeInput<T> {
// ignore: use_setters_to_change_properties, as method.
void bindToModel(GladeModel model) => _bindedModel = model;

static GladeInput<int> intInput({
static IntInput intInput({
required int value,
String? inputKey,
int? initialValue,
Expand Down Expand Up @@ -368,7 +370,7 @@ class GladeInput<T> {
);
}

static GladeInput<bool> boolInput({
static BooleanInput boolInput({
required bool value,
String? inputKey,
bool? initialValue,
Expand Down Expand Up @@ -404,7 +406,7 @@ class GladeInput<T> {
trackUnchanged: trackUnchanged,
);

static GladeInput<String> stringInput({
static StringInput stringInput({
String? inputKey,
String? value,
String? initialValue,
Expand Down
30 changes: 24 additions & 6 deletions glade_forms/lib/src/widgets/glade_model_debug_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class _Table extends StatelessWidget {
children: [
// Columns header.
TableRow(
decoration: const BoxDecoration(color: Colors.black12, border: Border(bottom: BorderSide())),
decoration: const BoxDecoration(color: Colors.black, border: Border(bottom: BorderSide())),
children: [
const _ColumnHeader('Input'),
if (showIsUnchanged) const _ColumnHeader('isUnchanged'),
Expand All @@ -213,7 +213,9 @@ class _Table extends StatelessWidget {
),
for (final (index, x) in inputs.indexed)
TableRow(
decoration: BoxDecoration(color: index.isEven ? Colors.white : const Color.fromARGB(255, 235, 234, 234)),
decoration: BoxDecoration(
color: index.isEven ? Theme.of(context).canvasColor : Theme.of(context).canvasColor.darken(0.2),
),
children: [
Padding(
padding: const EdgeInsets.only(left: 5),
Expand Down Expand Up @@ -305,10 +307,14 @@ class _StringValue extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Text(
x ?? '',
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(backgroundColor: const Color.fromARGB(255, 196, 222, 184)),
return ColoredBox(
color: Theme.of(context).brightness == Brightness.light
? const Color.fromARGB(255, 196, 222, 184)
: const Color.fromARGB(255, 15, 46, 0),
child: Text(
x ?? '',
//style: Theme.of(context).textTheme.bodyLarge?.copyWith(backgroundColor: ),
),
);
}
}
Expand Down Expand Up @@ -390,3 +396,15 @@ class _DangerStrips extends StatelessWidget {
return stripes;
}
}

extension _ColorExtensions on Color {
/// Returns color darkened by [amount].
Color darken([double amount = 0.1]) {
assert(amount >= 0 && amount <= 1, 'amount must be between 0 and 1');

final hsl = HSLColor.fromColor(this);
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));

return hslDark.toColor();
}
}
2 changes: 1 addition & 1 deletion glade_forms/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: glade_forms
description: A universal way to define form validators with support of translations.
version: 3.1.0
version: 3.1.1
repository: https://github.com/netglade/glade_forms
issue_tracker: https://github.com/netglade/glade_forms/issues
screenshots:
Expand Down

0 comments on commit 4f138c3

Please sign in to comment.