Skip to content

Commit

Permalink
Activate useful linter rules (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Jun 22, 2022
1 parent 75d87ba commit 31d1f7b
Show file tree
Hide file tree
Showing 32 changed files with 662 additions and 508 deletions.
5 changes: 3 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
avoid_print: false # Uncomment to disable the `avoid_print` rule
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
require_trailing_commas: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
121 changes: 67 additions & 54 deletions lib/src/yaru_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,22 @@ class _YaruCarouselState extends State<YaruCarousel> {
@override
Widget build(BuildContext context) {
return SizedBox(
height: widget.height,
width: widget.width,
child: Column(
children: [
_buildCarousel(),
...(widget.placeIndicator && widget.children.length > 1
? [
SizedBox(
height: widget.placeIndicatorMarginTop,
),
_buildPlaceIndicator()
]
: [])
],
));
height: widget.height,
width: widget.width,
child: Column(
children: [
_buildCarousel(),
...(widget.placeIndicator && widget.children.length > 1
? [
SizedBox(
height: widget.placeIndicatorMarginTop,
),
_buildPlaceIndicator()
]
: [])
],
),
);
}

Widget _buildCarousel() {
Expand Down Expand Up @@ -149,59 +150,70 @@ class _YaruCarouselState extends State<YaruCarousel> {

if (widget.navigationControls) {
return Expanded(
child: Stack(
children: [
carousel,
_buildNavigationButton(
child: Stack(
children: [
carousel,
_buildNavigationButton(
Alignment.centerLeft,
_isFirstPage() ? null : () => _animateToPreviousPage(),
widget.previousIcon ?? const Icon(Icons.arrow_back)),
_buildNavigationButton(
widget.previousIcon ?? const Icon(Icons.arrow_back),
),
_buildNavigationButton(
Alignment.centerRight,
_isLastPage() ? null : () => _animateToNextPage(),
widget.nextIcon ?? const Icon(Icons.arrow_forward)),
],
));
widget.nextIcon ?? const Icon(Icons.arrow_forward),
),
],
),
);
}

return Expanded(child: carousel);
}

Widget _buildNavigationButton(
AlignmentGeometry alignement, VoidCallback? onPressed, Widget icon) {
AlignmentGeometry alignement,
VoidCallback? onPressed,
Widget icon,
) {
return Positioned.fill(
child: Align(
alignment: alignement,
child: OutlinedButton(
child: Align(
alignment: alignement,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
shape: const CircleBorder(),
backgroundColor: Theme.of(context).colorScheme.background),
shape: const CircleBorder(),
backgroundColor: Theme.of(context).colorScheme.background,
),
onPressed: onPressed,
child: icon),
));
child: icon,
),
),
);
}

Widget _buildPlaceIndicator() {
return LayoutBuilder(builder: (context, constraints) {
const double dotSize = 12.0;

for (var layout in [
[48.0, constraints.maxWidth / 2],
[24.0, constraints.maxWidth / 3 * 2],
[12.0, constraints.maxWidth / 6 * 5]
]) {
final double dotSpacing = layout[0];
final double maxWidth = layout[1];

if (dotSize * widget.children.length +
dotSpacing * (widget.children.length - 1) <
maxWidth) {
return _buildDotIndicator(dotSize, dotSpacing);
return LayoutBuilder(
builder: (context, constraints) {
const double dotSize = 12.0;

for (var layout in [
[48.0, constraints.maxWidth / 2],
[24.0, constraints.maxWidth / 3 * 2],
[12.0, constraints.maxWidth / 6 * 5]
]) {
final double dotSpacing = layout[0];
final double maxWidth = layout[1];

if (dotSize * widget.children.length +
dotSpacing * (widget.children.length - 1) <
maxWidth) {
return _buildDotIndicator(dotSize, dotSpacing);
}
}
}

return _buildTextIndicator();
});
return _buildTextIndicator();
},
);
}

Widget _buildDotIndicator(double dotSize, double dotSpacing) {
Expand All @@ -220,10 +232,11 @@ class _YaruCarouselState extends State<YaruCarousel> {
width: dotSize,
height: dotSize,
decoration: BoxDecoration(
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(.3),
shape: BoxShape.circle),
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(.3),
shape: BoxShape.circle,
),
),
),
),
Expand Down
26 changes: 15 additions & 11 deletions lib/src/yaru_color_disk.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';

class YaruColorDisk extends StatelessWidget {
const YaruColorDisk(
{Key? key,
required this.onPressed,
required this.color,
required this.selected})
: super(key: key);
const YaruColorDisk({
Key? key,
required this.onPressed,
required this.color,
required this.selected,
}) : super(key: key);

final VoidCallback onPressed;
final Color color;
Expand All @@ -22,18 +22,22 @@ class YaruColorDisk extends StatelessWidget {
style: TextButton.styleFrom(
padding: const EdgeInsets.all(0),
shape: CircleBorder(
side: BorderSide(
color: selected
? Theme.of(context).primaryColor
: Colors.transparent)),
side: BorderSide(
color: selected
? Theme.of(context).primaryColor
: Colors.transparent,
),
),
),
onPressed: onPressed,
child: SizedBox(
height: 20,
width: 20,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100), color: color),
borderRadius: BorderRadius.circular(100),
color: color,
),
),
),
),
Expand Down
4 changes: 3 additions & 1 deletion lib/src/yaru_color_picker_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class YaruColorPickerButton extends StatelessWidget {
height: size / 2,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100), color: color),
borderRadius: BorderRadius.circular(100),
color: color,
),
),
),
),
Expand Down
33 changes: 17 additions & 16 deletions lib/src/yaru_compact_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ class _YaruCompactLayoutState extends State<YaruCompactLayout> {
return SafeArea(
child: Scaffold(
body: LayoutBuilder(
builder: (context, constraints) =>
constraints.maxWidth > widget.narrowLayoutMaxWidth
? YaruWideLayout(
labelType: widget.labelType,
pageItems: widget.pageItems,
initialIndex: _index == -1 ? _previousIndex : _index,
onSelected: _setIndex,
)
: YaruNarrowLayout(
showSelectedLabels: widget.showSelectedLabels,
showUnselectedLabels: widget.showUnselectedLabels,
bottomNavigationBarType: widget.bottomNavigationBarType,
pageItems: widget.pageItems,
initialIndex: _index == -1 ? _previousIndex : _index,
onSelected: _setIndex,
)),
builder: (context, constraints) =>
constraints.maxWidth > widget.narrowLayoutMaxWidth
? YaruWideLayout(
labelType: widget.labelType,
pageItems: widget.pageItems,
initialIndex: _index == -1 ? _previousIndex : _index,
onSelected: _setIndex,
)
: YaruNarrowLayout(
showSelectedLabels: widget.showSelectedLabels,
showUnselectedLabels: widget.showUnselectedLabels,
bottomNavigationBarType: widget.bottomNavigationBarType,
pageItems: widget.pageItems,
initialIndex: _index == -1 ? _previousIndex : _index,
onSelected: _setIndex,
),
),
),
);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/yaru_dialog_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class YaruDialogTitle extends StatelessWidget {
children: [
Padding(
padding: const EdgeInsets.only(
left: kDefaultPagePadding +
5, // Avoid title overflow on close button
right:
kDefaultPagePadding, // Avoid title overflow on close button
top: kDefaultPagePadding,
bottom: kDefaultPagePadding),
left:
kDefaultPagePadding + 5, // Avoid title overflow on close button
right: kDefaultPagePadding, // Avoid title overflow on close button
top: kDefaultPagePadding,
bottom: kDefaultPagePadding,
),
child: Row(
mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
Expand Down
14 changes: 10 additions & 4 deletions lib/src/yaru_draggable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ class _YaruDraggableState extends State<YaruDraggable> {
_moveOffset = const Offset(0, 0);
if (widget.onDragEnd != null) widget.onDragEnd!();
}),
child: Builder(builder: (context) {
return widget.childBuilder(
context, _position, _isDragging, _isHovering);
}),
child: Builder(
builder: (context) {
return widget.childBuilder(
context,
_position,
_isDragging,
_isHovering,
);
},
),
),
),
);
Expand Down
15 changes: 8 additions & 7 deletions lib/src/yaru_expandable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ class _YaruExpandableState extends State<YaruExpandable> {
],
),
AnimatedCrossFade(
firstChild: widget.child,
secondChild: widget.collapsedChild ?? Container(),
crossFadeState: _isExpanded
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
sizeCurve: _kAnimationCurve,
duration: _kAnimationDuration)
firstChild: widget.child,
secondChild: widget.collapsedChild ?? Container(),
crossFadeState: _isExpanded
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
sizeCurve: _kAnimationCurve,
duration: _kAnimationDuration,
)
],
);
}
Expand Down
31 changes: 19 additions & 12 deletions lib/src/yaru_expansion_panel_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ class YaruExpansionPanelList extends StatelessWidget {
Widget build(BuildContext context) {
final List<Widget> items = <Widget>[];
const EdgeInsets kExpandedEdgeInsets = EdgeInsets.symmetric(
vertical: _kPanelHeaderExpandedHeight - _kPanelHeaderCollapsedHeight);
vertical: _kPanelHeaderExpandedHeight - _kPanelHeaderCollapsedHeight,
);

for (int index = 0; index < children.length; index += 1) {
if (_isChildExpanded(index) &&
index != 0 &&
!_isChildExpanded(index - 1)) {
items.add(Divider(
key: _SaltedKey<BuildContext, int>(context, index * 2 - 1),
height: 10.0,
color: Colors.transparent,
));
items.add(
Divider(
key: _SaltedKey<BuildContext, int>(context, index * 2 - 1),
height: 10.0,
color: Colors.transparent,
),
);
}

final header = Row(
Expand Down Expand Up @@ -84,11 +87,13 @@ class YaruExpansionPanelList extends StatelessWidget {
BorderRadius borderRadius = index == 0
? BorderRadius.only(
topLeft: Radius.circular(_radiusValue),
topRight: Radius.circular(_radiusValue))
topRight: Radius.circular(_radiusValue),
)
: index == children.length - 1
? BorderRadius.only(
bottomLeft: Radius.circular(_radiusValue),
bottomRight: Radius.circular(_radiusValue))
bottomRight: Radius.circular(_radiusValue),
)
: const BorderRadius.all(Radius.zero);
items.add(
Container(
Expand Down Expand Up @@ -126,10 +131,12 @@ class YaruExpansionPanelList extends StatelessWidget {
);

if (index != children.length - 1 && _isChildExpanded(index)) {
items.add(SizedBox(
height: 10,
key: _SaltedKey<BuildContext, int>(context, index * 2 + 1),
));
items.add(
SizedBox(
height: 10,
key: _SaltedKey<BuildContext, int>(context, index * 2 + 1),
),
);
}
}

Expand Down

0 comments on commit 31d1f7b

Please sign in to comment.