Skip to content

Commit

Permalink
chore: enforce dart formatting on files (#272)
Browse files Browse the repository at this point in the history
* chore: format all files with dart format -l 120

* chore(ci): enforce formatting check in test ci
  • Loading branch information
smallTrogdor authored Jan 15, 2025
1 parent 23c3c74 commit f96f005
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 241 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- name: Install dependencies
run: flutter pub get

- name: Format check
run: dart format -l 120 -o none --set-exit-if-changed .

- name: Run Flutter test
id: test
run: flutter test
Expand Down
14 changes: 13 additions & 1 deletion CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ Please refer to the following guideline for detailed recommendations:

[Style guide for Flutter](https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md)

## Code style

Your code should adhere to the effective [dart style](https://dart.dev/effective-dart/style).

## Code formatting

You must adhere to the formatting described in the Flutter style guide.
According to the above recommended style, we check our code for formatting with the `dart format` cli in our CI
(before running src code generation, e.g. Mocks).
The only deviation is a line length of `120` compared to the standard guide. If your code does not follow these standards,
the CI will fail. We run this step:

```yml
- name: Format check
run: dart format -l 120 -o none --set-exit-if-changed .
```
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import 'package:provider/provider.dart';
import 'native_app.dart';

void main() {
runApp(ChangeNotifierProvider<AppState>(
create: (BuildContext context) => AppState(), child: MyApp()));
runApp(ChangeNotifierProvider<AppState>(create: (BuildContext context) => AppState(), child: MyApp()));
}
23 changes: 7 additions & 16 deletions lib/src/accordion/sbb_accordion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SBBAccordion extends StatefulWidget {
});

SBBAccordion.single({
Key? key,
Key? key,
required String title,
required Widget body,
bool isExpanded = false,
Expand All @@ -107,8 +107,7 @@ class SBBAccordion extends StatefulWidget {
),
],
titleMaxLines: titleMaxLines,
accordionCallback: (index, isExpanded) =>
singleAccordionCallback?.call(
accordionCallback: (index, isExpanded) => singleAccordionCallback?.call(
isExpanded,
),
backgroundColor: backgroundColor,
Expand Down Expand Up @@ -151,13 +150,10 @@ class _SBBAccordionState extends State<SBBAccordion> {
);
}

Container _buildAccordionChildren(
BuildContext context, SBBAccordionItem child, int i) {
Container _buildAccordionChildren(BuildContext context, SBBAccordionItem child, int i) {
final style = SBBControlStyles.of(context);
return Container(
decoration: BoxDecoration(
border:
Border.all(color: widget.borderColor ?? SBBColors.transparent)),
decoration: BoxDecoration(border: Border.all(color: widget.borderColor ?? SBBColors.transparent)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expand All @@ -174,9 +170,7 @@ class _SBBAccordionState extends State<SBBAccordion> {
child.title,
style: style.accordionTitleTextStyle,
maxLines: widget.titleMaxLines,
overflow: widget.titleMaxLines == null
? null
: TextOverflow.ellipsis,
overflow: widget.titleMaxLines == null ? null : TextOverflow.ellipsis,
),
),
),
Expand Down Expand Up @@ -213,9 +207,7 @@ class _SBBAccordionState extends State<SBBAccordion> {
curve: Curves.fastOutSlowIn,
),
sizeCurve: Curves.fastOutSlowIn,
crossFadeState: _isChildExpanded(i)
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
crossFadeState: _isChildExpanded(i) ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: kThemeAnimationDuration,
),
if (i < widget.children.length - 1) const Divider(),
Expand All @@ -234,8 +226,7 @@ class _ExpandIcon extends StatefulWidget {
_ExpandIconState createState() => _ExpandIconState();
}

class _ExpandIconState extends State<_ExpandIcon>
with SingleTickerProviderStateMixin {
class _ExpandIconState extends State<_ExpandIcon> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _iconTurns;

Expand Down
4 changes: 1 addition & 3 deletions lib/src/button/sbb_icon_form_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class SBBIconFormButton extends StatelessWidget {
shape: SBBTheme.allStates(const RoundedRectangleBorder()),
);
return TextButton(
style: SBBButtonStyles.of(context)
.iconFormStyle
?.overrideButtonStyle(baseStyle),
style: SBBButtonStyles.of(context).iconFormStyle?.overrideButtonStyle(baseStyle),
onPressed: onPressed,
focusNode: focusNode,
child: Icon(icon, size: sbbIconSizeSmall),
Expand Down
22 changes: 6 additions & 16 deletions lib/src/chip/sbb_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class SBBChip extends StatelessWidget {
decoration: ShapeDecoration(
shape: StadiumBorder(
side: BorderSide(
color:
_disabled ? style.disabledBorderColor! : style.borderColor!,
color: _disabled ? style.disabledBorderColor! : style.borderColor!,
),
),
),
Expand All @@ -63,16 +62,13 @@ class SBBChip extends StatelessWidget {
}

Padding _label(SBBChipStyle style) {
final labelTextStyle = _disabled
? style.labelTextStyle!.textStyleDisabled
: style.labelTextStyle!.textStyle;
final labelTextStyle = _disabled ? style.labelTextStyle!.textStyleDisabled : style.labelTextStyle!.textStyle;
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 6.0,
horizontal: 12.0,
).subtract(
EdgeInsets.only(
right: _showBadgeLabel || _showUnselectButton ? _kChipMargin : 0),
EdgeInsets.only(right: _showBadgeLabel || _showUnselectButton ? _kChipMargin : 0),
),
child: Text(
label,
Expand All @@ -83,9 +79,7 @@ class SBBChip extends StatelessWidget {
}

Widget _badge(SBBChipStyle style) {
final badgeTextStyle = _disabled
? style.badgeTextStyle!.textStyleDisabled
: style.badgeTextStyle!.textStyle;
final badgeTextStyle = _disabled ? style.badgeTextStyle!.textStyleDisabled : style.badgeTextStyle!.textStyle;
return _roundedContainer(
child: Text(
badgeLabel ?? '',
Expand All @@ -103,13 +97,9 @@ class SBBChip extends StatelessWidget {
child: _roundedContainer(
child: Icon(
SBBIcons.cross_small,
color: _disabled
? style.disabledUnselectButtonIconColor!
: style.unselectButtonIconColor!,
color: _disabled ? style.disabledUnselectButtonIconColor! : style.unselectButtonIconColor!,
),
color: _disabled
? style.disabledUnselectButtonColor!
: style.unselectButtonColor!,
color: _disabled ? style.disabledUnselectButtonColor! : style.unselectButtonColor!,
width: 24.0,
),
);
Expand Down
5 changes: 2 additions & 3 deletions lib/src/header/sbb_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SBBHeader extends StatelessWidget implements PreferredSizeWidget {
required this.logoTooltip,
this.actions,
this.blockSemantics,
}) : assert(actions == null || onPressedLogo == null);
}) : assert(actions == null || onPressedLogo == null);

final String title;
final Widget? leadingWidget;
Expand Down Expand Up @@ -208,8 +208,7 @@ class SBBHeader extends StatelessWidget implements PreferredSizeWidget {
excluding: onPressedLogo == null,
child: Container(
alignment: Alignment.centerRight,
padding:
const EdgeInsets.only(right: sbbDefaultSpacing / 2),
padding: const EdgeInsets.only(right: sbbDefaultSpacing / 2),
height: kToolbarHeight,
width: customLeadingWidth ? leadingWidth : kToolbarHeight,
child: IconButton(
Expand Down
8 changes: 2 additions & 6 deletions lib/src/input_trigger/sbb_input_trigger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ class SBBInputTrigger extends StatelessWidget {
TextStyle _valueTextStyle(SBBTextFieldStyle style) {
return !enabled
? style.textStyleDisabled!
: (!_hasValue
? style.placeholderTextStyle
: (_hasError ? style.textStyleError : style.textStyle))!;
: (!_hasValue ? style.placeholderTextStyle : (_hasError ? style.textStyleError : style.textStyle))!;
}
}

Expand Down Expand Up @@ -233,9 +231,7 @@ class SBBInputTriggerIconWidget extends StatelessWidget {
}

final style = SBBControlStyles.of(context).textField!;
final iconColor = enabled
? (error ? style.prefixIconColorError : style.iconColor)
: style.iconColorDisabled;
final iconColor = enabled ? (error ? style.prefixIconColorError : style.iconColor) : style.iconColorDisabled;

if (onPressed == null) {
return Padding(
Expand Down
27 changes: 9 additions & 18 deletions lib/src/link/sbb_link_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class SBBLinkTextState extends State<SBBLinkText> {
final plainTextSections = widget.text.split(combinedPattern);
final linkSections = combinedPattern.allMatches(widget.text).toList();
final List<TextSpan> inlineSpans = [];
for (var i = 0;
i < math.max(plainTextSections.length, linkSections.length);
i++) {
for (var i = 0; i < math.max(plainTextSections.length, linkSections.length); i++) {
if (i < plainTextSections.length) {
inlineSpans.add(
TextSpan(
Expand All @@ -81,10 +79,8 @@ class SBBLinkTextState extends State<SBBLinkText> {
_isHoveredValues.add(false);

final tapGestureRecognizer = TapGestureRecognizer();
tapGestureRecognizer.onTapDown = (TapDownDetails details) =>
setState(() => _isPressedValues[i] = true);
tapGestureRecognizer.onTapCancel =
() => setState(() => _isPressedValues[i] = false);
tapGestureRecognizer.onTapDown = (TapDownDetails details) => setState(() => _isPressedValues[i] = true);
tapGestureRecognizer.onTapCancel = () => setState(() => _isPressedValues[i] = false);
tapGestureRecognizer.onTap = () {
widget.onLaunch(url);
setState(() => _isPressedValues[i] = false);
Expand All @@ -98,8 +94,7 @@ class SBBLinkTextState extends State<SBBLinkText> {
_isHoveredValues[i] = false;
}),
text: text ?? url,
style: _linkTextStyle(
_isPressedValues[i] == true, _isHoveredValues[i] == true),
style: _linkTextStyle(_isPressedValues[i] == true, _isHoveredValues[i] == true),
recognizer: tapGestureRecognizer,
),
);
Expand All @@ -111,8 +106,7 @@ class SBBLinkTextState extends State<SBBLinkText> {
TextStyle? _resolveTextStyle(SBBBaseStyle style) {
final hasCustomStyle = widget.style != null;
final textStyle = hasCustomStyle
? widget.style!.copyWith(
color: widget.style!.color ?? style.defaultTextStyle!.color)
? widget.style!.copyWith(color: widget.style!.color ?? style.defaultTextStyle!.color)
: style.defaultTextStyle;
return textStyle;
}
Expand All @@ -122,15 +116,12 @@ class SBBLinkTextState extends State<SBBLinkText> {
final controlStyle = SBBControlStyles.of(context);
final hasCustomStyle = widget.style != null;
final textStyle = hasCustomStyle
? widget.style!.copyWith(
color: widget.style!.color ?? style.defaultTextStyle!.color)
? widget.style!.copyWith(color: widget.style!.color ?? style.defaultTextStyle!.color)
: style.defaultTextStyle;
final linkStyle = hasCustomStyle
? textStyle!.copyWith(color: controlStyle.linkTextStyle!.color)
: controlStyle.linkTextStyle;
final linkStyle =
hasCustomStyle ? textStyle!.copyWith(color: controlStyle.linkTextStyle!.color) : controlStyle.linkTextStyle;
final linkStylePressed = hasCustomStyle
? textStyle!
.copyWith(color: controlStyle.linkTextStyleHighlighted!.color)
? textStyle!.copyWith(color: controlStyle.linkTextStyleHighlighted!.color)
: controlStyle.linkTextStyleHighlighted;

return (isPressed ? linkStylePressed : linkStyle)!;
Expand Down
22 changes: 6 additions & 16 deletions lib/src/list_item/sbb_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class SBBListItem extends StatefulWidget {
),
child: Icon(
trailingIcon,
color: isEnabled
? style.iconColor
: style.iconColorDisabled,
color: isEnabled ? style.iconColor : style.iconColorDisabled,
),
);
},
Expand Down Expand Up @@ -117,8 +115,7 @@ class _SBBListItemState extends State<SBBListItem> {
child: Semantics(
button: isEnabled,
child: Material(
color:
isEnabled ? style.backgroundColor : style.backgroundColorDisabled,
color: isEnabled ? style.backgroundColor : style.backgroundColorDisabled,
child: InkWell(
splashColor: style.backgroundColorHighlighted,
focusColor: style.backgroundColorHighlighted,
Expand Down Expand Up @@ -151,23 +148,18 @@ class _SBBListItemState extends State<SBBListItem> {
children: [
if (widget.leadingIcon != null)
Padding(
padding:
const EdgeInsetsDirectional.only(
padding: const EdgeInsetsDirectional.only(
end: sbbDefaultSpacing * 0.5,
),
child: Icon(
widget.leadingIcon,
color: isEnabled
? style.iconColor
: style.iconColorDisabled,
color: isEnabled ? style.iconColor : style.iconColorDisabled,
),
),
Expanded(
child: Text(
widget.title,
style: isEnabled
? style.textStyle
: style.textStyleDisabled,
style: isEnabled ? style.textStyle : style.textStyleDisabled,
maxLines: widget.titleMaxLines,
overflow: wrapTitle ? TextOverflow.clip : TextOverflow.ellipsis,
),
Expand All @@ -182,9 +174,7 @@ class _SBBListItemState extends State<SBBListItem> {
),
child: Text(
widget.subtitle!,
style: isEnabled
? style.secondaryTextStyle
: style.secondaryTextStyleDisabled,
style: isEnabled ? style.secondaryTextStyle : style.secondaryTextStyleDisabled,
maxLines: widget.subtitleMaxLines,
overflow: wrapSubtitleTitle ? TextOverflow.clip : TextOverflow.ellipsis,
),
Expand Down
8 changes: 3 additions & 5 deletions lib/src/loading_indicator/sbb_loading_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SBBLoadingIndicator extends StatelessWidget {

class LoadingAnimation extends StatefulWidget {
const LoadingAnimation({
super.key,
super.key,
required this.squareWidth,
required this.squareHeight,
required this.squareSpacing,
Expand All @@ -138,8 +138,7 @@ class LoadingAnimation extends StatefulWidget {
LoadingAnimationState createState() => LoadingAnimationState();
}

class LoadingAnimationState extends State<LoadingAnimation>
with SingleTickerProviderStateMixin {
class LoadingAnimationState extends State<LoadingAnimation> with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _loadingSquareOne;
late Animation<double> _loadingSquareTwo;
Expand Down Expand Up @@ -185,8 +184,7 @@ class LoadingAnimationState extends State<LoadingAnimation>
curve: Curves.linear,
),
);
_container =
Tween<Offset>(begin: Offset.zero, end: const Offset(-0.2, 0.0)).animate(
_container = Tween<Offset>(begin: Offset.zero, end: const Offset(-0.2, 0.0)).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.linear,
Expand Down
Loading

0 comments on commit f96f005

Please sign in to comment.