diff --git a/lib/flutter_switch.dart b/lib/flutter_switch.dart index e30ca12..ccea9f0 100644 --- a/lib/flutter_switch.dart +++ b/lib/flutter_switch.dart @@ -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), @@ -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(); } @@ -431,12 +451,16 @@ class _FlutterSwitchState extends State 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, + ), ), ); } @@ -446,14 +470,18 @@ class _FlutterSwitchState extends State 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, ); }