buttonContent method

  1. @override
Widget buttonContent(
  1. BuildContext context, {
  2. Key? key,
  3. Set<MaterialState>? materialStates,
  4. ButtonType type = ButtonType.Normal,
  5. String title = '',
  6. String subtitle = '',
  7. Widget? leadingWidget,
  8. AccessoryType accessoryType = AccessoryType.None,
  9. Map<String, dynamic>? extraInfo,
})
override

Button Content This generates the internal contents of a button cell with an optional icon/image, title, subtitle, and accessory Note: the callback to handle the button press is handled in the main settings cell, so it isn't passed down to this content method

  • context the current BuildContext
  • materialStates a set of the current states this cell is in (pressed, selected, disabled, etc)
  • type a button type (Normal, Cancel, Destructive, or Custom)
  • title main text description
  • subtitle secondary text description
  • leadingWidget an optional leading image/icon
  • accessoryType can indicate if a disclosure arrow, checkmark, or other symbol should be on the trailing side of cell
  • extraInfo a map where you can pass additional info through to your subclasses to be used however you need

Implementation

@override
Widget buttonContent(BuildContext context, {Key? key, Set<MaterialState>? materialStates, ButtonType type = ButtonType.Normal, String title = '', String subtitle = '', Widget? leadingWidget, AccessoryType accessoryType = AccessoryType.None, Map<String, dynamic>? extraInfo}) {
  materialStates ??= <MaterialState>{};
  var accessoryWidget = this.accessoryWidget(context, accessoryType: accessoryType, materialStates: materialStates, extraInfo: extraInfo);

  var titleTextStyle = this.titleTextStyle(context, materialStates: materialStates, extraInfo: extraInfo);
  var subtitleTextStyle = this.subtitleTextStyle(context, materialStates: materialStates, extraInfo: extraInfo);
  var textColor = Colors.transparent;
  switch (type) {
    case ButtonType.Normal:
      textColor = primaryColor();
      break;
    case ButtonType.Destructive:
      textColor = Colors.red;
      break;
    case ButtonType.Cancel:
      textColor = Colors.grey;
      break;
    case ButtonType.Custom:
      break;
  }

  if (materialStates.isDisabled) {
    titleTextStyle = titleTextStyle.copyWith(color: textColor.withAlpha(100));
  } else {
    titleTextStyle = titleTextStyle.copyWith(color: textColor);
  }

  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, overflow: TextOverflow.ellipsis),
                if (subtitle.isNotEmpty) Text('$subtitle', style: subtitleTextStyle, overflow: TextOverflow.ellipsis),
              ],
            ),
          ),
        ),
        if (accessoryWidget != null) horizontalPadding(context, extraInfo: extraInfo),
        if (accessoryWidget != null) accessoryWidget,
        trailingCellPadding(context, extraInfo: extraInfo),
      ],
    ),
  );
}