Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modifiers in spec #333

Merged
merged 32 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8a9e4b0
chore: bump flutter version to 3.19.0
tilucasoli Jul 5, 2024
bf8625d
Merge branch 'main' into chore/bump-flutter-3.19.0
leoafarias Jul 6, 2024
bc67687
Merge branch 'main' into chore/bump-flutter-3.19.0
leoafarias Jul 7, 2024
d9aef57
fix deprecates
tilucasoli Jul 8, 2024
08fdae1
fix tests
tilucasoli Jul 8, 2024
6269ba2
fix DCM warnings
tilucasoli Jul 8, 2024
39bf800
Add deprecated tests
tilucasoli Jul 8, 2024
58465a6
fix tests
tilucasoli Jul 8, 2024
26d2be3
Update text_widget_test.dart
tilucasoli Jul 8, 2024
c73bd39
Revert "fix DCM warnings"
tilucasoli Jul 9, 2024
5f2703e
use generated code
tilucasoli Jul 9, 2024
3ab0d7e
feat: inline modifiers
tilucasoli Jun 27, 2024
ab43fb2
add modifiers in specs
tilucasoli Jun 27, 2024
7056fcf
Update melos.yaml
tilucasoli Jun 27, 2024
003b779
Update widget_modifiers_util.dart
tilucasoli Jun 27, 2024
f4828e6
rename RenderInlineModifiers to RenderSpecModifiers
tilucasoli Jun 28, 2024
673fb13
reusing utilities
tilucasoli Jun 28, 2024
42bf992
Update type_ref_repository.dart
tilucasoli Jun 28, 2024
3d37519
update specs
tilucasoli Jun 28, 2024
584385d
deprecate
tilucasoli Jul 2, 2024
10cedd9
Updates on conditional logic
leoafarias Jul 3, 2024
2ad7be5
Update widget_modifier_widget_test.dart
tilucasoli Jul 9, 2024
e7eafa9
Merge branch 'main' into feat/modifiers-in-spec
tilucasoli Jul 9, 2024
4a137f9
Merge branch 'main' into feat/modifiers-in-spec
tilucasoli Jul 9, 2024
1488c60
lint fixes
tilucasoli Jul 9, 2024
6de8270
Merge branch 'feat/modifiers-in-spec' of https://github.com/conceptad…
tilucasoli Jul 9, 2024
a4acf4f
Update text_style_token_test.dart
tilucasoli Jul 9, 2024
a950171
fix animations
tilucasoli Jul 9, 2024
f295ae2
fix animation
tilucasoli Jul 10, 2024
e3f8bc9
Moved updateSpecs to didUpdateWidget
leoafarias Jul 10, 2024
37c6f7a
Update widget_modifier_widget_test.dart
tilucasoli Jul 10, 2024
15474dd
rename wrap to modifiers
tilucasoli Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/todo_list/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:mix/mix.dart';
import 'package:todo_list/pages/todo_list_page.dart';

import 'pages/todo_list_page.dart';
import 'style/design_tokens.dart';

void main() {
Expand Down
26 changes: 9 additions & 17 deletions examples/todo_list/lib/style/components/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ class TodoCheckbox extends StatelessWidget {
$box.borderRadius(3),
scaleEffect(),
outlinePattern(),
$icon.size(16),
$icon.color.ref($token.color.surface),
$icon.wrap.opacity(0),
$icon.wrap.padding.top(5),
$icon.wrap.scale(0.5),
_CheckboxVariant.checked(
$icon.wrap.padding.top(0),
$icon.wrap.scale(2),
$icon.wrap.opacity(1),
$box.color.ref($token.color.primary),
$box.border.color.ref($token.color.primary),
),
Expand All @@ -41,24 +49,8 @@ class TodoCheckbox extends StatelessWidget {
.animate(
duration: const Duration(milliseconds: 150),
),
child: StyledIcon(
child: const StyledIcon(
Icons.check,
style: Style(
$icon.weight(16),
$icon.color.ref($token.color.surface),
$with.opacity(0),
$with.padding.top(5),
_CheckboxVariant.checked(
$with.padding.top(0),
$with.opacity(1),
),
)
.applyVariant(
value ? _CheckboxVariant.checked : _CheckboxVariant.unchecked,
)
.animate(
duration: const Duration(milliseconds: 300),
),
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ scripts:
custom_lint_analyze:
run: dart pub global activate custom_lint && melos exec --depends-on="mix_lint" custom_lint

mix_exports:
run: melos exec --scope="packages/mix" dart run ./scripts/exports.dart
description: Generate exports for the mix package

analyze:
run: |
dcm analyze --fatal-warnings --fatal-style --fatal-performance .
Expand Down
3 changes: 3 additions & 0 deletions packages/mix/lib/src/attributes/attributes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export 'enum/enum_util.dart';
export 'gap/gap_util.dart';
export 'gap/spacing_side_dto.dart';
export 'gradient/gradient_dto.dart';
export 'modifiers/widget_modifiers_data.dart';
export 'modifiers/widget_modifiers_data_dto.dart';
export 'modifiers/widget_modifiers_util.dart';
export 'nested_style/nested_style_attribute.dart';
export 'nested_style/nested_style_util.dart';
export 'scalars/scalar_util.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../../core/modifier.dart';

class WidgetModifiersData {
// ignore: avoid-dynamic
final List<WidgetModifierSpec<dynamic>> value;
const WidgetModifiersData(this.value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import '../../core/core.dart';
import 'widget_modifiers_data.dart';

class WidgetModifiersDataDto extends Dto<WidgetModifiersData> {
final List<WidgetModifierAttribute> value;

const WidgetModifiersDataDto(this.value);

@override
WidgetModifiersDataDto merge(WidgetModifiersDataDto? other) {
if (other == null) return this;
final thisMap = AttributeMap(value);
final otherMap = AttributeMap(other.value);
final mergedMap = thisMap.merge(otherMap).values;

return WidgetModifiersDataDto(mergedMap);
}

@override
WidgetModifiersData resolve(MixData mix) {
return WidgetModifiersData(value.map((e) => e.resolve(mix)).toList());
}

@override
WidgetModifiersData get defaultValue => const WidgetModifiersData([]);

@override
List<Object?> get props => [value];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '../../core/core.dart';
import '../../modifiers/modifiers.dart';
import 'widget_modifiers_data_dto.dart';

final class SpecModifierUtility<T extends Attribute>
extends ModifierUtility<T, WidgetModifiersDataDto> {
SpecModifierUtility(super.builder);

@override
T only(WidgetModifierAttribute attribute) {
return builder(WidgetModifiersDataDto([attribute]));
}
}
3 changes: 2 additions & 1 deletion packages/mix/lib/src/core/attributes_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class AttributeMap<T extends Attribute> {

Attr? attributeOfType<Attr extends SpecAttribute>() => _map?[Attr] as Attr?;

Iterable<Attr> whereType<Attr extends T>() => _map?.values.whereType() ?? [];
Iterable<Attr> whereType<Attr extends T>() =>
_map?.values.whereType<Attr>() ?? [];

AttributeMap<T> merge(AttributeMap<T>? other) {
return other == null ? this : AttributeMap([...values, ...other.values]);
Expand Down
13 changes: 13 additions & 0 deletions packages/mix/lib/src/core/factory/mix_data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: avoid-dynamic
import 'package:flutter/widgets.dart';

import '../../attributes/animated/animated_data.dart';
Expand Down Expand Up @@ -59,6 +60,13 @@ class MixData {
@visibleForTesting
AttributeMap get attributes => _attributes;

List<WidgetModifierSpec<dynamic>> get modifiers {
return _attributes
.whereType<WidgetModifierAttribute>()
.map((e) => e.resolve(this))
.toList();
}

MixData toInheritable() {
final inheritableAttributes = _attributes.values.where(
(attr) => attr is! WidgetModifierAttribute,
Expand All @@ -75,6 +83,11 @@ class MixData {
return _mergeAttributes(attributes) ?? attributes.last;
}

List<WidgetModifierSpec<dynamic>>
modifiersOf<M extends WidgetModifierSpec<dynamic>>() {
return modifiers.whereType<M>().toList();
}

Iterable<A> whereType<A extends StyledAttribute>() {
return _attributes.whereType();
}
Expand Down
1 change: 0 additions & 1 deletion packages/mix/lib/src/core/modifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'utility.dart';

abstract base class WidgetModifierSpec<Self extends WidgetModifierSpec<Self>>
extends Spec<Self> {
@override
const WidgetModifierSpec({super.animated});

static WidgetModifierSpec? lerpValue(
Expand Down
11 changes: 9 additions & 2 deletions packages/mix/lib/src/core/spec.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:mix_annotations/mix_annotations.dart';

import '../attributes/animated/animated_data.dart';
import '../attributes/animated/animated_data_dto.dart';
import '../attributes/modifiers/widget_modifiers_data.dart';
import '../attributes/modifiers/widget_modifiers_data_dto.dart';
import '../internal/compare_mixin.dart';
import 'attribute.dart';
import 'factory/mix_data.dart';
Expand All @@ -11,7 +14,10 @@ import 'utility.dart';
abstract class Spec<T extends Spec<T>> with EqualityMixin {
final AnimatedData? animated;

const Spec({this.animated});
@MixableProperty(utilities: [MixableUtility(alias: 'wrap')])
final WidgetModifiersData? modifiers;

const Spec({this.animated, this.modifiers});

Type get type => T;

Expand All @@ -31,8 +37,9 @@ abstract class Spec<T extends Spec<T>> with EqualityMixin {
/// The [Self] type represents the concrete implementation of the attribute, while the [Value] type represents the resolvable value.
abstract base class SpecAttribute<Value> extends StyledAttribute {
final AnimatedDataDto? animated;
final WidgetModifiersDataDto? modifiers;

const SpecAttribute({this.animated});
const SpecAttribute({this.animated, this.modifiers});

Value resolve(MixData mix);
@override
Expand Down
17 changes: 10 additions & 7 deletions packages/mix/lib/src/core/styled_widget.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:flutter/widgets.dart';

import '../modifiers/render_widget_modifier.dart';
import 'factory/mix_data.dart';
import 'factory/mix_provider.dart';
import 'factory/style_mix.dart';
import '../modifiers/modifiers.dart';
import 'core.dart';

/// An abstract widget for applying custom styles.
///
Expand Down Expand Up @@ -60,16 +58,21 @@ abstract class StyledWidget extends StatelessWidget {
}

Widget applyModifiers(MixData mix, Widget child) {
final modifiers = mix
.whereType<WidgetModifierAttribute>()
.map((e) => e.resolve(mix))
.toList();

return mix.isAnimated
? RenderAnimatedModifiers(
mix: mix,
orderOfModifiers: orderOfModifiers,
modifiers: modifiers,
duration: mix.animation!.duration,
orderOfModifiers: orderOfModifiers,
curve: mix.animation!.curve,
child: child,
)
: RenderModifiers(
mix: mix,
modifiers: modifiers,
orderOfModifiers: orderOfModifiers,
child: child,
);
Expand Down
Loading
Loading