From a1d423090c854ebe319a0fa03fd6e5c4007b1387 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Thu, 25 Aug 2022 11:07:53 +0600 Subject: [PATCH] fix(adaptive-list-tile): dialog content not updating when content has changed --- lib/components/Settings/Settings.dart | 27 +++++++++++------ lib/components/Shared/AdaptiveListTile.dart | 33 +++++++++++---------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/components/Settings/Settings.dart b/lib/components/Settings/Settings.dart index 30a61fff..278d6ea5 100644 --- a/lib/components/Settings/Settings.dart +++ b/lib/components/Settings/Settings.dart @@ -66,7 +66,7 @@ class Settings extends HookConsumerWidget { AdaptiveListTile( leading: const Icon(Icons.dark_mode_outlined), title: const Text("Theme"), - trailing: DropdownButton( + trailing: (context, update) => DropdownButton( value: preferences.themeMode, items: const [ DropdownMenuItem( @@ -89,6 +89,7 @@ class Settings extends HookConsumerWidget { onChanged: (value) { if (value != null) { preferences.setThemeMode(value); + update?.call(() {}); } }, ), @@ -131,7 +132,7 @@ class Settings extends HookConsumerWidget { "Recommendation Country", style: Theme.of(context).textTheme.caption, ), - trailing: ConstrainedBox( + trailing: (context, update) => ConstrainedBox( constraints: const BoxConstraints(maxWidth: 250), child: DropdownButton( isExpanded: true, @@ -149,6 +150,7 @@ class Settings extends HookConsumerWidget { preferences.setRecommendationMarket( value as String, ); + update?.call(() {}); }, ), ), @@ -171,7 +173,7 @@ class Settings extends HookConsumerWidget { ), subtitle: const Text("(Case sensitive)"), breakOn: Breakpoints.lg, - trailing: ConstrainedBox( + trailing: (context, update) => ConstrainedBox( constraints: const BoxConstraints(maxWidth: 450), child: TextField( controller: ytSearchFormatController, @@ -188,6 +190,7 @@ class Settings extends HookConsumerWidget { ), onSubmitted: (value) { preferences.setYtSearchFormat(value); + update?.call(() {}); }, ), ), @@ -228,7 +231,7 @@ class Settings extends HookConsumerWidget { color: Theme.of(context).primaryColor, ), ), - trailing: ElevatedButton( + trailing: (context, update) => ElevatedButton( child: Text("Connect with Spotify".toUpperCase()), onPressed: () { GoRouter.of(context).push("/login"); @@ -258,7 +261,8 @@ class Settings extends HookConsumerWidget { "Track Match Algorithm", maxLines: 1, ), - trailing: DropdownButton( + trailing: (context, update) => + DropdownButton( value: preferences.trackMatchAlgorithm, items: const [ DropdownMenuItem( @@ -281,6 +285,7 @@ class Settings extends HookConsumerWidget { onChanged: (value) { if (value != null) { preferences.setTrackMatchAlgorithm(value); + update?.call(() {}); } }, ), @@ -288,7 +293,8 @@ class Settings extends HookConsumerWidget { AdaptiveListTile( leading: const Icon(Icons.multitrack_audio_rounded), title: const Text("Audio Quality"), - trailing: DropdownButton( + trailing: (context, update) => + DropdownButton( value: preferences.audioQuality, items: const [ DropdownMenuItem( @@ -305,6 +311,7 @@ class Settings extends HookConsumerWidget { onChanged: (value) { if (value != null) { preferences.setAudioQuality(value); + update?.call(() {}); } }, ), @@ -346,7 +353,7 @@ class Settings extends HookConsumerWidget { fontWeight: FontWeight.bold, ), ), - trailing: ElevatedButton.icon( + trailing: (context, update) => ElevatedButton.icon( icon: const Icon(Icons.favorite_outline_rounded), label: const Text("Please Sponsor/Donate"), style: ElevatedButton.styleFrom( @@ -355,8 +362,10 @@ class Settings extends HookConsumerWidget { padding: const EdgeInsets.all(15), ), onPressed: () { - launchUrlString("https://opencollective.com/spotube", - mode: LaunchMode.externalApplication); + launchUrlString( + "https://opencollective.com/spotube", + mode: LaunchMode.externalApplication, + ); }, ), ), diff --git a/lib/components/Shared/AdaptiveListTile.dart b/lib/components/Shared/AdaptiveListTile.dart index 7a1cad72..ce2e004b 100644 --- a/lib/components/Shared/AdaptiveListTile.dart +++ b/lib/components/Shared/AdaptiveListTile.dart @@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:spotube/hooks/useBreakpoints.dart'; class AdaptiveListTile extends HookWidget { - final Widget? trailing; + final Widget Function(BuildContext, StateSetter?)? trailing; final Widget? title; final Widget? subtitle; final Widget? leading; @@ -27,7 +27,8 @@ class AdaptiveListTile extends HookWidget { return ListTile( title: title, subtitle: subtitle, - trailing: breakpoint.isLessThan(breakOn) ? null : trailing, + trailing: + breakpoint.isLessThan(breakOn) ? null : trailing?.call(context, null), leading: leading, onTap: breakpoint.isLessThan(breakOn) ? () { @@ -35,20 +36,22 @@ class AdaptiveListTile extends HookWidget { showDialog( context: context, builder: (context) { - return AlertDialog( - title: title != null - ? Row( - children: [ - if (leading != null) ...[ - leading!, - const SizedBox(width: 5) + return StatefulBuilder(builder: (context, update) { + return AlertDialog( + title: title != null + ? Row( + children: [ + if (leading != null) ...[ + leading!, + const SizedBox(width: 5) + ], + Flexible(child: title!), ], - Flexible(child: title!), - ], - ) - : null, - content: trailing, - ); + ) + : null, + content: trailing?.call(context, update), + ); + }); }, ); }