Skip to content

Commit

Permalink
refactor: switch to flutter_lints
Browse files Browse the repository at this point in the history
closes #201
  • Loading branch information
GroovinChip committed Apr 22, 2022
1 parent bd11dcc commit 38bb8fc
Show file tree
Hide file tree
Showing 34 changed files with 171 additions and 131 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.12.4+2]
* Switch over to `flutter_lints`

## [0.12.4+1]
* Improve visual design of `MacosPopupButton` and `MacosPulldownButton`, to better match the styling and translucency effect of Apple design.
* Remove unnecessary properties of `MacosPopupButton`
Expand Down
12 changes: 7 additions & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
linter:
rules:
- avoid_relative_lib_imports
- prefer_const_constructors
- use_key_in_widget_constructors
include: package:flutter_lints/flutter.yaml

#linter:
# rules:
# - avoid_relative_lib_imports
# - prefer_const_constructors
# - use_key_in_widget_constructors

analyzer:
plugins:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.12.4+1"
version: "0.12.4+2"
matcher:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/buttons/back_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class MacosBackButtonState extends State<MacosBackButton>
}

@override
void didUpdateWidget(MacosBackButton old) {
super.didUpdateWidget(old);
void didUpdateWidget(MacosBackButton oldWidget) {
super.didUpdateWidget(oldWidget);
_setTween();
}

Expand Down
14 changes: 7 additions & 7 deletions lib/src/buttons/help_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class HelpButtonState extends State<HelpButton>
}

@override
void didUpdateWidget(HelpButton old) {
super.didUpdateWidget(old);
void didUpdateWidget(HelpButton oldWidget) {
super.didUpdateWidget(oldWidget);
_setTween();
}

Expand Down Expand Up @@ -198,18 +198,18 @@ class HelpButtonState extends State<HelpButton>
decoration: BoxDecoration(
shape: BoxShape.circle,
color: !enabled ? disabledColor : backgroundColor,
boxShadow: [
const BoxShadow(
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(-0.1, -0.1),
),
const BoxShadow(
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(0.1, 0.1),
),
const BoxShadow(
BoxShadow(
color: CupertinoColors.tertiarySystemFill,
offset: const Offset(0, 0),
offset: Offset(0, 0),
),
],
),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/buttons/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class MacosIconButtonState extends State<MacosIconButton>
}

@override
void didUpdateWidget(MacosIconButton old) {
super.didUpdateWidget(old);
void didUpdateWidget(MacosIconButton oldWidget) {
super.didUpdateWidget(oldWidget);
_setTween();
}

Expand Down Expand Up @@ -250,6 +250,7 @@ class MacosIconButtonState extends State<MacosIconButton>
child: DecoratedBox(
decoration: BoxDecoration(
shape: widget.shape,
// ignore: prefer_if_null_operators
borderRadius: widget.borderRadius != null
? widget.borderRadius
: widget.shape == BoxShape.rectangle
Expand Down Expand Up @@ -316,6 +317,7 @@ class MacosIconButtonTheme extends InheritedTheme {
return buttonTheme?.data ?? MacosTheme.of(context).macosIconButtonTheme;
}

@override
Widget wrap(BuildContext context, Widget child) {
return MacosIconButtonTheme(data: data, child: child);
}
Expand Down
18 changes: 9 additions & 9 deletions lib/src/buttons/popup_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,10 @@ class _MacosPopupRoute<T> extends PopupRoute<_MacosPopupRouteResult<T>> {
double menuTop = (buttonTop - selectedItemOffset) -
(itemHeights[selectedIndex] - buttonRect.height) / 2.0;
double preferredMenuHeight = 8.0;
if (items.isNotEmpty)
if (items.isNotEmpty) {
preferredMenuHeight +=
itemHeights.reduce((double total, double height) => total + height);
}

// If there are too many elements in the menu, we need to shrink it down
// so it is at most the computedMaxHeight.
Expand Down Expand Up @@ -666,10 +667,8 @@ class _MacosPopupRoutePage<T> extends StatelessWidget {
// treating the items as if their heights were all equal to _kMinInteractiveDimension.
final _MenuLimits menuLimits =
route.getMenuLimits(buttonRect, constraints.maxHeight, selectedIndex);
if (route.scrollController == null) {
route.scrollController =
ScrollController(initialScrollOffset: menuLimits.scrollOffset);
}
route.scrollController ??=
ScrollController(initialScrollOffset: menuLimits.scrollOffset);

final TextDirection? textDirection = Directionality.maybeOf(context);
final Widget menu = _MacosPopupMenu<T>(
Expand Down Expand Up @@ -1142,8 +1141,8 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>

void _handleTap() {
final TextDirection? textDirection = Directionality.maybeOf(context);
final EdgeInsetsGeometry menuMargin =
const EdgeInsetsDirectional.only(start: 4.0, end: 4.0);
const EdgeInsetsGeometry menuMargin =
EdgeInsetsDirectional.only(start: 4.0, end: 4.0);

final List<_MenuItem<T>> menuItems = <_MenuItem<T>>[
for (int index = 0; index < widget.items!.length; index += 1)
Expand Down Expand Up @@ -1227,8 +1226,9 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
if (widget.hint != null || (!_enabled && widget.disabledHint != null)) {
Widget displayedHint =
_enabled ? widget.hint! : widget.disabledHint ?? widget.hint!;
if (widget.selectedItemBuilder == null)
if (widget.selectedItemBuilder == null) {
displayedHint = _MacosPopupMenuItemContainer(child: displayedHint);
}

hintIndex = items.length;
items.add(IgnorePointer(
Expand Down Expand Up @@ -1407,7 +1407,7 @@ class _UpDownCaretsPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final radius = 4.0;
const radius = 4.0;
final vPadding = size.height / 8 + 1.25;
final hPadding = 2 * size.height / 8 + 1.25;

Expand Down
9 changes: 5 additions & 4 deletions lib/src/buttons/pulldown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,10 @@ class _MacosPulldownRoute extends PopupRoute {

double menuTop = buttonTop + buttonRect.height;
double preferredMenuHeight = 8.0;
if (items.isNotEmpty)
if (items.isNotEmpty) {
preferredMenuHeight +=
itemHeights.reduce((double total, double height) => total + height);
}

// If there are too many elements in the menu, we need to shrink it down
// so it is at most the computedMaxHeight.
Expand Down Expand Up @@ -808,8 +809,8 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>

void _handleTap() {
final TextDirection? textDirection = Directionality.maybeOf(context);
final EdgeInsetsGeometry menuMargin =
const EdgeInsetsDirectional.only(start: 4.0, end: 4.0);
const EdgeInsetsGeometry menuMargin =
EdgeInsetsDirectional.only(start: 4.0, end: 4.0);

final List<_MenuItem> menuItems = <_MenuItem>[
for (int index = 0; index < widget.items!.length; index += 1)
Expand Down Expand Up @@ -1102,7 +1103,7 @@ class _DownCaretPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final radius = 4.0;
const radius = 4.0;
final hPadding = size.height / 3;

/// Draw background
Expand Down
12 changes: 6 additions & 6 deletions lib/src/buttons/push_button.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: prefer_if_null_operators

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:macos_ui/macos_ui.dart';
Expand All @@ -17,10 +19,8 @@ const EdgeInsetsGeometry _kLargeButtonPadding = EdgeInsets.symmetric(
horizontal: 8.0,
);

const BorderRadius _kSmallButtonRadius =
const BorderRadius.all(Radius.circular(5.0));
const BorderRadius _kLargeButtonRadius =
const BorderRadius.all(Radius.circular(7.0));
const BorderRadius _kSmallButtonRadius = BorderRadius.all(Radius.circular(5.0));
const BorderRadius _kLargeButtonRadius = BorderRadius.all(Radius.circular(7.0));

/// A macOS-style button.
class PushButton extends StatefulWidget {
Expand Down Expand Up @@ -164,8 +164,8 @@ class PushButtonState extends State<PushButton>
}

@override
void didUpdateWidget(PushButton old) {
super.didUpdateWidget(old);
void didUpdateWidget(PushButton oldWidget) {
super.didUpdateWidget(oldWidget);
_setTween();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/dialogs/macos_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class _MacosAlertDialogRoute<T> extends PopupRoute<T> {
return ScaleTransition(
scale: CurvedAnimation(
parent: animation,
curve: _SubtleBounceCurve(),
curve: const _SubtleBounceCurve(),
),
child: FadeTransition(
opacity: CurvedAnimation(
Expand All @@ -353,7 +353,7 @@ class _MacosAlertDialogRoute<T> extends PopupRoute<T> {
}

class _SubtleBounceCurve extends Curve {
_SubtleBounceCurve();
const _SubtleBounceCurve();

@override
double transform(double t) {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/fields/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,9 @@ class _MacosTextFieldState extends State<MacosTextField>
bool _shouldShowSelectionHandles(SelectionChangedCause? cause) {
// When the text field is activated by something that doesn't trigger the
// selection overlay, we shouldn't show the handles either.
if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar)
if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar) {
return false;
}

// On macOS, we don't show handles when the selection is collapsed.
if (_effectiveController.selection.isCollapsed) return false;
Expand Down Expand Up @@ -1152,8 +1153,9 @@ class _MacosTextFieldState extends State<MacosTextField>
final bool textChanged =
_effectiveController.text.isNotEmpty;
_effectiveController.clear();
if (widget.onChanged != null && textChanged)
if (widget.onChanged != null && textChanged) {
widget.onChanged!(_effectiveController.text);
}
}
: null,
child: Padding(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/icon/macos_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ class MacosIcon extends StatelessWidget {

final iconOpacity = iconTheme.opacity ?? 1.0;
Color iconColor = color ?? iconTheme.color!;
if (iconOpacity != 1.0)
if (iconOpacity != 1.0) {
iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
}

Widget iconWidget = RichText(
overflow: TextOverflow.visible,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/indicators/capacity_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CapacityIndicatorCell extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
return SizedBox(
height: 16,
child: CustomPaint(
painter: _CapacityCellPainter(
Expand Down Expand Up @@ -213,7 +213,7 @@ class _CapacityCellPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final radius = 2.0;
const radius = 2.0;

/// Draw background
canvas.drawRRect(
Expand All @@ -224,8 +224,8 @@ class _CapacityCellPainter extends CustomPainter {
/// Draw inside
canvas.drawRRect(
BorderRadius.horizontal(
left: Radius.circular(radius),
right: value == 100 ? Radius.circular(radius) : Radius.zero,
left: const Radius.circular(radius),
right: value == 100 ? const Radius.circular(radius) : Radius.zero,
).toRRect(
Offset.zero & Size(size.width * (value / 100).clamp(0, 1), size.height),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/indicators/rating_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ class RatingIndicator extends StatelessWidget {

void _handleUpdate(Offset lp) {
double value = lp.dx / iconSize;
if (value.isNegative)
if (value.isNegative) {
value = 0;
else if (value > amount) value = amount.toDouble();
} else if (value > amount) {
value = amount.toDouble();
}
onChanged?.call(value);
}

Expand Down
14 changes: 9 additions & 5 deletions lib/src/indicators/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,29 @@ class MacosScrollbar extends StatelessWidget {
minThumbLength: theme.minThumbLength,
radius: theme.radius,
thickness: m.MaterialStateProperty.resolveWith((states) {
if (states.contains(m.MaterialState.hovered))
if (states.contains(m.MaterialState.hovered)) {
return theme.hoveringThickness ?? theme.thickness;
}
return theme.thickness;
}),
thumbColor: m.MaterialStateProperty.resolveWith((states) {
if (states.contains(m.MaterialState.hovered))
if (states.contains(m.MaterialState.hovered)) {
return theme.hoveringThumbColor ?? theme.thumbColor;
else if (states.contains(m.MaterialState.dragged))
} else if (states.contains(m.MaterialState.dragged)) {
return theme.draggingThumbColor ?? theme.thumbColor;
}
return theme.thumbColor;
}),
trackBorderColor: m.MaterialStateProperty.resolveWith((states) {
if (states.contains(m.MaterialState.hovered))
if (states.contains(m.MaterialState.hovered)) {
return theme.hoveringTrackBorderColor ?? theme.trackBorderColor;
}
return theme.trackBorderColor;
}),
trackColor: m.MaterialStateProperty.resolveWith((states) {
if (states.contains(m.MaterialState.hovered))
if (states.contains(m.MaterialState.hovered)) {
return theme.hoveringTrackColor ?? theme.trackColor;
}
return theme.trackColor;
}),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layout/content_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ContentArea extends StatelessWidget {
///
/// The width of this
/// widget is automatically calculated in [MacosScaffoldScope].
ContentArea({
const ContentArea({
required this.builder,
this.minWidth = 300,
}) : super(key: const Key('macos_scaffold_content_area'));
Expand Down
Loading

0 comments on commit 38bb8fc

Please sign in to comment.