From b037040846b9a7ab8b7f4e0b0e2dc8b94e4661b7 Mon Sep 17 00:00:00 2001 From: Alexander Hentschel Date: Mon, 29 May 2023 15:41:45 +0200 Subject: [PATCH] Add compact SettingsTile option --- lib/src/tiles/platforms/android_settings_tile.dart | 8 ++++++-- lib/src/tiles/platforms/ios_settings_tile.dart | 8 ++++++-- lib/src/tiles/platforms/web_settings_tile.dart | 8 ++++++-- lib/src/tiles/settings_tile.dart | 7 +++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/src/tiles/platforms/android_settings_tile.dart b/lib/src/tiles/platforms/android_settings_tile.dart index ca59908..5f8e127 100644 --- a/lib/src/tiles/platforms/android_settings_tile.dart +++ b/lib/src/tiles/platforms/android_settings_tile.dart @@ -14,6 +14,7 @@ class AndroidSettingsTile extends StatelessWidget { required this.activeSwitchColor, required this.enabled, required this.trailing, + required this.compact, Key? key, }) : super(key: key); @@ -28,6 +29,7 @@ class AndroidSettingsTile extends StatelessWidget { final bool enabled; final Color? activeSwitchColor; final Widget? trailing; + final bool compact; @override Widget build(BuildContext context) { @@ -38,6 +40,8 @@ class AndroidSettingsTile extends StatelessWidget { ? onToggle == null && onPressed == null : onPressed == null; + final double tilePadding = this.compact ? 10 : 19; + return IgnorePointer( ignoring: !enabled, child: Material( @@ -73,8 +77,8 @@ class AndroidSettingsTile extends StatelessWidget { padding: EdgeInsetsDirectional.only( start: 24, end: 24, - bottom: 19 * scaleFactor, - top: 19 * scaleFactor, + bottom: tilePadding * scaleFactor, + top: tilePadding * scaleFactor, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/src/tiles/platforms/ios_settings_tile.dart b/lib/src/tiles/platforms/ios_settings_tile.dart index c86f350..8bfbe5c 100644 --- a/lib/src/tiles/platforms/ios_settings_tile.dart +++ b/lib/src/tiles/platforms/ios_settings_tile.dart @@ -15,6 +15,7 @@ class IOSSettingsTile extends StatefulWidget { required this.activeSwitchColor, required this.enabled, required this.trailing, + required this.compact, Key? key, }) : super(key: key); @@ -29,6 +30,7 @@ class IOSSettingsTile extends StatefulWidget { final bool enabled; final Color? activeSwitchColor; final Widget? trailing; + final bool compact; @override _IOSSettingsTileState createState() => _IOSSettingsTileState(); @@ -176,6 +178,8 @@ class _IOSSettingsTileState extends State { ) { final scaleFactor = MediaQuery.of(context).textScaleFactor; + final double tilePadding = widget.compact ? 7 : 12.5; + return GestureDetector( behavior: HitTestBehavior.translucent, onTap: widget.onPressed == null @@ -227,8 +231,8 @@ class _IOSSettingsTileState extends State { Expanded( child: Padding( padding: EdgeInsetsDirectional.only( - top: 12.5 * scaleFactor, - bottom: 12.5 * scaleFactor, + top: tilePadding * scaleFactor, + bottom: tilePadding * scaleFactor, ), child: DefaultTextStyle( style: TextStyle( diff --git a/lib/src/tiles/platforms/web_settings_tile.dart b/lib/src/tiles/platforms/web_settings_tile.dart index 6ff2608..4c5e13c 100644 --- a/lib/src/tiles/platforms/web_settings_tile.dart +++ b/lib/src/tiles/platforms/web_settings_tile.dart @@ -15,6 +15,7 @@ class WebSettingsTile extends StatelessWidget { required this.activeSwitchColor, required this.enabled, required this.trailing, + required this.compact, Key? key, }) : super(key: key); @@ -29,12 +30,15 @@ class WebSettingsTile extends StatelessWidget { final bool enabled; final Widget? trailing; final Color? activeSwitchColor; + final bool compact; @override Widget build(BuildContext context) { final theme = SettingsTheme.of(context); final scaleFactor = MediaQuery.of(context).textScaleFactor; + final double tilePadding = this.compact ? 10 : 19; + final cantShowAnimation = tileType == SettingsTileType.switchTile ? onToggle == null && onPressed == null : onPressed == null; @@ -74,8 +78,8 @@ class WebSettingsTile extends StatelessWidget { padding: EdgeInsetsDirectional.only( start: 24, end: 24, - bottom: 19 * scaleFactor, - top: 19 * scaleFactor, + bottom: tilePadding * scaleFactor, + top: tilePadding * scaleFactor, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/src/tiles/settings_tile.dart b/lib/src/tiles/settings_tile.dart index dbf8faa..8ba0bcc 100644 --- a/lib/src/tiles/settings_tile.dart +++ b/lib/src/tiles/settings_tile.dart @@ -17,6 +17,7 @@ class SettingsTile extends AbstractSettingsTile { this.description, this.onPressed, this.enabled = true, + this.compact = false, Key? key, }) : super(key: key) { onToggle = null; @@ -33,6 +34,7 @@ class SettingsTile extends AbstractSettingsTile { this.description, this.onPressed, this.enabled = true, + this.compact = false, Key? key, }) : super(key: key) { onToggle = null; @@ -51,6 +53,7 @@ class SettingsTile extends AbstractSettingsTile { this.description, this.onPressed, this.enabled = true, + this.compact = false, Key? key, }) : super(key: key) { value = null; @@ -78,6 +81,7 @@ class SettingsTile extends AbstractSettingsTile { late final SettingsTileType tileType; late final bool? initialValue; late final bool enabled; + late final bool compact; @override Widget build(BuildContext context) { @@ -96,6 +100,7 @@ class SettingsTile extends AbstractSettingsTile { leading: leading, title: title, enabled: enabled, + compact: compact, activeSwitchColor: activeSwitchColor, initialValue: initialValue ?? false, trailing: trailing, @@ -113,6 +118,7 @@ class SettingsTile extends AbstractSettingsTile { title: title, trailing: trailing, enabled: enabled, + compact: compact, activeSwitchColor: activeSwitchColor, initialValue: initialValue ?? false, ); @@ -127,6 +133,7 @@ class SettingsTile extends AbstractSettingsTile { title: title, enabled: enabled, trailing: trailing, + compact: compact, activeSwitchColor: activeSwitchColor, initialValue: initialValue ?? false, );