Skip to content

Commit

Permalink
chore(deps)!: update dart_style from v2 to v3 (#10)
Browse files Browse the repository at this point in the history
- Use latestLanguageVersion in DartFormatter
- Use caret syntax for dependencies

---------

Co-authored-by: Nando Schär <[email protected]>
  • Loading branch information
nschaer92 and Nando Schär authored Feb 7, 2025
1 parent 8f3fde1 commit 9c9d3e2
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 153 deletions.
13 changes: 6 additions & 7 deletions example/lib/app.colors.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions example/lib/app.screens.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions lib/src/builder/base_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ abstract base class DesignSystemBuilder implements Builder {

buildStep.writeAsString(
output,
DartFormatter().format(outputLib
.accept(DartEmitter.scoped(
useNullSafetySyntax: true, orderDirectives: true))
.toString()));
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(outputLib
.accept(DartEmitter.scoped(
useNullSafetySyntax: true, orderDirectives: true))
.toString()));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/color_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class ColorBuilder extends DesignSystemBuilder {
..name = 'opacity'
..type = refer('double')))
..lambda = true
..body = Code('color.withOpacity(opacity)')))
..body = Code('color.withValues(alpha: opacity)')))
..methods.add(Method((b) => b
..name = 'fromColor'
..static = true
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
build:
code_builder:
dart_style:
build: ^2.4.2
code_builder: ^4.10.1
dart_style: ^3.0.1

dev_dependencies:
build_test:
Expand Down
39 changes: 18 additions & 21 deletions test/builder/color_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ enum AppColor {
final _i1.Color color;
_i1.Color withOpacity(double opacity) => color.withOpacity(opacity);
static AppColor fromColor(
_i1.Color color, [
AppColor? orElse,
]) =>
AppColor.values.firstWhere((e) => e.color == color,
orElse: orElse == null ? null : () => orElse);
_i1.Color withOpacity(double opacity) => color.withValues(alpha: opacity);
static AppColor fromColor(_i1.Color color, [AppColor? orElse]) =>
AppColor.values.firstWhere(
(e) => e.color == color,
orElse: orElse == null ? null : () => orElse,
);
}
''';

Expand Down Expand Up @@ -124,13 +123,12 @@ enum AppColor {
final _i1.Color color;
_i1.Color withOpacity(double opacity) => color.withOpacity(opacity);
static AppColor fromColor(
_i1.Color color, [
AppColor? orElse,
]) =>
AppColor.values.firstWhere((e) => e.color == color,
orElse: orElse == null ? null : () => orElse);
_i1.Color withOpacity(double opacity) => color.withValues(alpha: opacity);
static AppColor fromColor(_i1.Color color, [AppColor? orElse]) =>
AppColor.values.firstWhere(
(e) => e.color == color,
orElse: orElse == null ? null : () => orElse,
);
}
'''
},
Expand Down Expand Up @@ -171,13 +169,12 @@ enum AppColor {
final _i1.Color color;
_i1.Color withOpacity(double opacity) => color.withOpacity(opacity);
static AppColor fromColor(
_i1.Color color, [
AppColor? orElse,
]) =>
AppColor.values.firstWhere((e) => e.color == color,
orElse: orElse == null ? null : () => orElse);
_i1.Color withOpacity(double opacity) => color.withValues(alpha: opacity);
static AppColor fromColor(_i1.Color color, [AppColor? orElse]) =>
AppColor.values.firstWhere(
(e) => e.color == color,
orElse: orElse == null ? null : () => orElse,
);
}
'''
},
Expand Down
78 changes: 36 additions & 42 deletions test/builder/radius_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,23 @@ enum AppBorderRadius {
bool topRight = false,
bool bottomLeft = false,
bool bottomRight = false,
}) =>
_i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
}) => _i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
_i1.BorderRadius combine({
AppBorderRadius? topLeft,
AppBorderRadius? topRight,
AppBorderRadius? bottomLeft,
AppBorderRadius? bottomRight,
}) =>
all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}) => all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}
''';

Expand Down Expand Up @@ -163,25 +161,23 @@ enum AppBorderRadius {
bool topRight = false,
bool bottomLeft = false,
bool bottomRight = false,
}) =>
_i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
}) => _i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
_i1.BorderRadius combine({
AppBorderRadius? topLeft,
AppBorderRadius? topRight,
AppBorderRadius? bottomLeft,
AppBorderRadius? bottomRight,
}) =>
all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}) => all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}
'''
},
Expand Down Expand Up @@ -238,25 +234,23 @@ enum AppBorderRadius {
bool topRight = false,
bool bottomLeft = false,
bool bottomRight = false,
}) =>
_i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
}) => _i1.BorderRadius.only(
topLeft: topLeft ? asRadius : _i1.Radius.zero,
topRight: topRight ? asRadius : _i1.Radius.zero,
bottomLeft: bottomLeft ? asRadius : _i1.Radius.zero,
bottomRight: bottomRight ? asRadius : _i1.Radius.zero,
);
_i1.BorderRadius combine({
AppBorderRadius? topLeft,
AppBorderRadius? topRight,
AppBorderRadius? bottomLeft,
AppBorderRadius? bottomRight,
}) =>
all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}) => all.copyWith(
topLeft: topLeft?.asRadius,
topRight: topRight?.asRadius,
bottomLeft: bottomLeft?.asRadius,
bottomRight: bottomRight?.asRadius,
);
}
'''
},
Expand Down
66 changes: 45 additions & 21 deletions test/builder/screen_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,28 @@ T responsiveValue<T>(
T? lg,
T? xl,
}) {
final width = context != null
? _i1.View.of(context).physicalSize.width
: _i1.WidgetsBinding.instance.platformDispatcher.views.first.physicalSize
.width;
final width =
context != null
? _i1.View.of(context).physicalSize.width
: _i1
.WidgetsBinding
.instance
.platformDispatcher
.views
.first
.physicalSize
.width;
final values = {
AppBreakpoints.xl: xl,
AppBreakpoints.lg: lg,
AppBreakpoints.md: md,
AppBreakpoints.sm: sm,
};
return (values.entries
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue) as T);
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue)
as T);
}
''';

Expand Down Expand Up @@ -166,18 +174,26 @@ T responsiveValue<T>(
T? tablet,
T? desktop,
}) {
final width = context != null
? _i1.View.of(context).physicalSize.width
: _i1.WidgetsBinding.instance.platformDispatcher.views.first.physicalSize
.width;
final width =
context != null
? _i1.View.of(context).physicalSize.width
: _i1
.WidgetsBinding
.instance
.platformDispatcher
.views
.first
.physicalSize
.width;
final values = {
AppBreakpoints.desktop: desktop,
AppBreakpoints.tablet: tablet,
};
return (values.entries
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue) as T);
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue)
as T);
}
'''
},
Expand Down Expand Up @@ -242,18 +258,26 @@ T responsiveValue<T>(
T? screen1,
T? screen2,
}) {
final width = context != null
? _i1.View.of(context).physicalSize.width
: _i1.WidgetsBinding.instance.platformDispatcher.views.first.physicalSize
.width;
final width =
context != null
? _i1.View.of(context).physicalSize.width
: _i1
.WidgetsBinding
.instance
.platformDispatcher
.views
.first
.physicalSize
.width;
final values = {
AppBreakpoints.screen2: screen2,
AppBreakpoints.screen1: screen1,
};
return (values.entries
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue) as T);
.skipWhile((e) => e.key > width)
.map((e) => e.value)
.firstWhere((e) => e != null, orElse: () => defaultValue)
as T);
}
'''
},
Expand Down
Loading

0 comments on commit 9c9d3e2

Please sign in to comment.