switchContent method
Widget
switchContent(
- BuildContext context, {
- Key? key,
- Set<
MaterialState> ? materialStates, - String title = '',
- String subtitle = '',
- bool value = false,
- Widget? leadingWidget,
- AccessoryType accessoryType = AccessoryType.None,
- required dynamic onChanged(),
- Map<
String, dynamic> ? extraInfo,
override
Switch Content This generates the internal contents of a toggle/switch cell with an optional icon/image, title, subtitle, value (used to set the initial value of the switch) and accessory
context
the current BuildContextmaterialStates
a set of the current states this cell is in (pressed, selected, disabled, etc)title
main text descriptionsubtitle
secondary text descriptionvalue
current value for this setting/cellleadingWidget
an optional leading image/iconaccessoryType
can indicate if a disclosure arrow, checkmark, or other symbol should be on the trailing side of cellonChanged
callback method called when the value of the swich changesextraInfo
a map where you can pass additional info through to your subclasses to be used however you need
Implementation
@override
Widget switchContent(BuildContext context, {Key? key, Set<MaterialState>? materialStates, String title = '', String subtitle = '', bool value = false, Widget? leadingWidget, AccessoryType accessoryType = AccessoryType.None, required Function(bool) onChanged, Map<String, dynamic>? extraInfo}) {
var accessoryWidget = this.accessoryWidget(context, accessoryType: accessoryType, materialStates: materialStates, extraInfo: extraInfo);
return Container(
key: key,
color: Colors.transparent,
height: rowHeight(context, extraInfo: extraInfo),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
leadingCellPadding(context, extraInfo: extraInfo),
if (leadingWidget != null) wrappedLeadingWidget(context, extraInfo: extraInfo, child: leadingWidget),
if (leadingWidget != null) horizontalPadding(context, extraInfo: extraInfo),
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (title.isNotEmpty) Text('$title', style: titleTextStyle(context, materialStates: materialStates, extraInfo: extraInfo), overflow: TextOverflow.ellipsis),
if (subtitle.isNotEmpty) Text('$subtitle', style: subtitleTextStyle(context, materialStates: materialStates, extraInfo: extraInfo), overflow: TextOverflow.ellipsis),
],
),
),
),
horizontalPadding(context, extraInfo: extraInfo),
Expanded(
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: CupertinoSwitch(
activeColor: switchActiveColor(context, materialStates: materialStates, extraInfo: extraInfo),
trackColor: switchTrackColor(context, materialStates: materialStates, extraInfo: extraInfo),
value: value,
onChanged: onChanged,
),
),
),
if (accessoryWidget != null) horizontalPadding(context, extraInfo: extraInfo),
if (accessoryWidget != null) accessoryWidget,
trailingCellPadding(context, extraInfo: extraInfo),
],
),
);
}