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

null safety improvements #68

Merged
merged 1 commit into from Oct 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/toggle_switch.dart
Expand Up @@ -65,7 +65,7 @@ class ToggleSwitch extends StatefulWidget {
final double iconSize;

/// Divider margin
final double? dividerMargin;
final double dividerMargin;

/// Border width
final double? borderWidth;
Expand Down Expand Up @@ -154,13 +154,13 @@ class _ToggleSwitchState extends State<ToggleSwitch>
/// Inactive background color
Color? inactiveBgColor;

/// Inctive foreground color
/// Inactive foreground color
Color? inactiveFgColor;

/// Border color
List<Color>? borderColor;

/// Border widtth
/// Border width
double? borderWidth;

/// Maintain selection state.
Expand Down Expand Up @@ -242,9 +242,7 @@ class _ToggleSwitchState extends State<ToggleSwitch>
/// Sets same active background color for all items if active background colors list is empty.
/// Sets different active background color for current item by matching index if active background colors list is not empty
if (active) {
bgColor = widget.activeBgColors == null
? activeBgColor
: (widget.activeBgColors![index ~/ 2] ?? activeBgColor);
bgColor = widget.activeBgColors?[index ~/ 2] ?? activeBgColor;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortening the expression

}

if (index % 2 == 1) {
Expand All @@ -261,10 +259,9 @@ class _ToggleSwitchState extends State<ToggleSwitch>
margin: widget.isVertical
? EdgeInsets.symmetric(
horizontal:
activeDivider ? 0.0 : widget.dividerMargin!)
activeDivider ? 0.0 : widget.dividerMargin)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dividerMargin allowed to set null so could cause exception

: EdgeInsets.symmetric(
vertical:
activeDivider ? 0.0 : widget.dividerMargin!),
vertical: activeDivider ? 0.0 : widget.dividerMargin),
);
} else {
/// Matches corner radius of active switch to that of border
Expand Down Expand Up @@ -437,12 +434,10 @@ class _ToggleSwitchState extends State<ToggleSwitch>
setState(() => widget.initialLabelIndex = index);
}
}
if (widget.onToggle != null) {
if (notifyNull) {
widget.onToggle!(null);
} else {
widget.onToggle!(index);
}
if (notifyNull) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small improvement

widget.onToggle?.call(null);
} else {
widget.onToggle?.call(index);
}
}

Expand Down