Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions lib/flutter_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class FlutterSwitch extends StatefulWidget {
this.inactiveIcon,
this.duration = const Duration(milliseconds: 200),
this.disabled = false,
this.activeTextStyle,
this.inactiveTextStyle,
this.activeTextAlignment = Alignment.centerLeft,
this.inactiveTextAlignment = Alignment.centerLeft,
}) : assert(
(switchBorder == null || activeSwitchBorder == null) &&
(switchBorder == null || inactiveSwitchBorder == null),
Expand Down Expand Up @@ -251,6 +255,22 @@ class FlutterSwitch extends StatefulWidget {
/// Defaults to the value of false.
final bool disabled;

/// The text style to use on the text value when the switch is on.
/// This parameter is only necessary when [showOnOff] property is true.
/// The use of this overrides the [activeTextColor] and [activeTextFontWeight] properties.
final TextStyle? activeTextStyle;

/// The text style to use on the text value when the switch is off.
/// /// This parameter is only necessary when [showOnOff] property is true.
/// The use of this overrides the [inactiveTextColor] and [inactiveTextFontWeight] properties.
final TextStyle? inactiveTextStyle;

/// The alignment of the text when the switch is on.
final Alignment activeTextAlignment;

/// The alignment of the text when the switch is off.
final Alignment inactiveTextAlignment;

@override
_FlutterSwitchState createState() => _FlutterSwitchState();
}
Expand Down Expand Up @@ -431,12 +451,16 @@ class _FlutterSwitchState extends State<FlutterSwitch>

Widget get _activeText {
if (widget.showOnOff) {
return Text(
widget.activeText ?? "On",
style: TextStyle(
color: widget.activeTextColor,
fontWeight: _activeTextFontWeight,
fontSize: widget.valueFontSize,
return Align(
alignment: widget.activeTextAlignment,
child: Text(
widget.activeText ?? "On",
style: widget.activeTextStyle ??
TextStyle(
color: widget.activeTextColor,
fontWeight: _activeTextFontWeight,
fontSize: widget.valueFontSize,
),
),
);
}
Expand All @@ -446,14 +470,18 @@ class _FlutterSwitchState extends State<FlutterSwitch>

Widget get _inactiveText {
if (widget.showOnOff) {
return Text(
widget.inactiveText ?? "Off",
style: TextStyle(
color: widget.inactiveTextColor,
fontWeight: _inactiveTextFontWeight,
fontSize: widget.valueFontSize,
return Align(
alignment: widget.inactiveTextAlignment,
child: Text(
widget.inactiveText ?? "Off",
style: widget.inactiveTextStyle ??
TextStyle(
color: widget.inactiveTextColor,
fontWeight: _inactiveTextFontWeight,
fontSize: widget.valueFontSize,
),
textAlign: TextAlign.right,
),
textAlign: TextAlign.right,
);
}

Expand Down