import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings_theme.dart'; /// One row of a [SettingsGroup]: Material [ListTile], Cupertino /// [CupertinoListTile]. The subtitle wraps (the Cupertino tile otherwise caps /// it at one line), so addresses and status details stay readable at large /// text. class SettingsRow extends StatelessWidget { const SettingsRow({ super.key, required this.title, this.subtitle, this.leading, this.trailing, this.onTap, this.chevron = false, this.action = false, this.enabled = true, }); final Widget title; final Widget? subtitle; final Widget? leading; final Widget? trailing; final VoidCallback? onTap; /// A navigation row: shows the platform's disclosure chevron. final bool chevron; /// A command row (Reconnect, Add server): the title takes the accent /// colour, as a button would. final bool action; final bool enabled; Widget _wrapping(Widget child) => Builder( builder: (context) => DefaultTextStyle( style: DefaultTextStyle.of(context).style, child: child, ), ); @override Widget build(BuildContext context) { final tap = enabled ? onTap : null; final subtitle = this.subtitle; if (usesCupertinoControls(context)) { final accent = CupertinoTheme.of(context).primaryColor; final disabled = CupertinoColors.tertiaryLabel.resolveFrom(context); return CupertinoListTile( leading: leading == null ? null : IconTheme.merge( data: IconThemeData(color: enabled ? accent : disabled), child: leading!, ), title: DefaultTextStyle.merge( style: TextStyle( color: !enabled ? disabled : action ? accent : null, ), child: title, ), subtitle: subtitle == null ? null : _wrapping(subtitle), trailing: trailing ?? (chevron ? const CupertinoListTileChevron() : null), onTap: tap, ); } final scheme = Theme.of(context).colorScheme; return ListTile( enabled: enabled, leading: leading, iconColor: action ? scheme.primary : null, textColor: action ? scheme.primary : null, title: title, subtitle: subtitle, trailing: trailing ?? (chevron ? const Icon(Icons.chevron_right) : null), onTap: tap, ); } }