fix(adaptive-list-tile): dialog content not updating when content has changed

This commit is contained in:
Kingkor Roy Tirtho 2022-08-25 11:07:53 +06:00
parent 307a8e21df
commit a1d423090c
2 changed files with 36 additions and 24 deletions

View File

@ -66,7 +66,7 @@ class Settings extends HookConsumerWidget {
AdaptiveListTile( AdaptiveListTile(
leading: const Icon(Icons.dark_mode_outlined), leading: const Icon(Icons.dark_mode_outlined),
title: const Text("Theme"), title: const Text("Theme"),
trailing: DropdownButton<ThemeMode>( trailing: (context, update) => DropdownButton<ThemeMode>(
value: preferences.themeMode, value: preferences.themeMode,
items: const [ items: const [
DropdownMenuItem( DropdownMenuItem(
@ -89,6 +89,7 @@ class Settings extends HookConsumerWidget {
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
preferences.setThemeMode(value); preferences.setThemeMode(value);
update?.call(() {});
} }
}, },
), ),
@ -131,7 +132,7 @@ class Settings extends HookConsumerWidget {
"Recommendation Country", "Recommendation Country",
style: Theme.of(context).textTheme.caption, style: Theme.of(context).textTheme.caption,
), ),
trailing: ConstrainedBox( trailing: (context, update) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 250), constraints: const BoxConstraints(maxWidth: 250),
child: DropdownButton( child: DropdownButton(
isExpanded: true, isExpanded: true,
@ -149,6 +150,7 @@ class Settings extends HookConsumerWidget {
preferences.setRecommendationMarket( preferences.setRecommendationMarket(
value as String, value as String,
); );
update?.call(() {});
}, },
), ),
), ),
@ -171,7 +173,7 @@ class Settings extends HookConsumerWidget {
), ),
subtitle: const Text("(Case sensitive)"), subtitle: const Text("(Case sensitive)"),
breakOn: Breakpoints.lg, breakOn: Breakpoints.lg,
trailing: ConstrainedBox( trailing: (context, update) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 450), constraints: const BoxConstraints(maxWidth: 450),
child: TextField( child: TextField(
controller: ytSearchFormatController, controller: ytSearchFormatController,
@ -188,6 +190,7 @@ class Settings extends HookConsumerWidget {
), ),
onSubmitted: (value) { onSubmitted: (value) {
preferences.setYtSearchFormat(value); preferences.setYtSearchFormat(value);
update?.call(() {});
}, },
), ),
), ),
@ -228,7 +231,7 @@ class Settings extends HookConsumerWidget {
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
), ),
), ),
trailing: ElevatedButton( trailing: (context, update) => ElevatedButton(
child: Text("Connect with Spotify".toUpperCase()), child: Text("Connect with Spotify".toUpperCase()),
onPressed: () { onPressed: () {
GoRouter.of(context).push("/login"); GoRouter.of(context).push("/login");
@ -258,7 +261,8 @@ class Settings extends HookConsumerWidget {
"Track Match Algorithm", "Track Match Algorithm",
maxLines: 1, maxLines: 1,
), ),
trailing: DropdownButton<SpotubeTrackMatchAlgorithm>( trailing: (context, update) =>
DropdownButton<SpotubeTrackMatchAlgorithm>(
value: preferences.trackMatchAlgorithm, value: preferences.trackMatchAlgorithm,
items: const [ items: const [
DropdownMenuItem( DropdownMenuItem(
@ -281,6 +285,7 @@ class Settings extends HookConsumerWidget {
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
preferences.setTrackMatchAlgorithm(value); preferences.setTrackMatchAlgorithm(value);
update?.call(() {});
} }
}, },
), ),
@ -288,7 +293,8 @@ class Settings extends HookConsumerWidget {
AdaptiveListTile( AdaptiveListTile(
leading: const Icon(Icons.multitrack_audio_rounded), leading: const Icon(Icons.multitrack_audio_rounded),
title: const Text("Audio Quality"), title: const Text("Audio Quality"),
trailing: DropdownButton<AudioQuality>( trailing: (context, update) =>
DropdownButton<AudioQuality>(
value: preferences.audioQuality, value: preferences.audioQuality,
items: const [ items: const [
DropdownMenuItem( DropdownMenuItem(
@ -305,6 +311,7 @@ class Settings extends HookConsumerWidget {
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
preferences.setAudioQuality(value); preferences.setAudioQuality(value);
update?.call(() {});
} }
}, },
), ),
@ -346,7 +353,7 @@ class Settings extends HookConsumerWidget {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
trailing: ElevatedButton.icon( trailing: (context, update) => ElevatedButton.icon(
icon: const Icon(Icons.favorite_outline_rounded), icon: const Icon(Icons.favorite_outline_rounded),
label: const Text("Please Sponsor/Donate"), label: const Text("Please Sponsor/Donate"),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
@ -355,8 +362,10 @@ class Settings extends HookConsumerWidget {
padding: const EdgeInsets.all(15), padding: const EdgeInsets.all(15),
), ),
onPressed: () { onPressed: () {
launchUrlString("https://opencollective.com/spotube", launchUrlString(
mode: LaunchMode.externalApplication); "https://opencollective.com/spotube",
mode: LaunchMode.externalApplication,
);
}, },
), ),
), ),

View File

@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:spotube/hooks/useBreakpoints.dart'; import 'package:spotube/hooks/useBreakpoints.dart';
class AdaptiveListTile extends HookWidget { class AdaptiveListTile extends HookWidget {
final Widget? trailing; final Widget Function(BuildContext, StateSetter?)? trailing;
final Widget? title; final Widget? title;
final Widget? subtitle; final Widget? subtitle;
final Widget? leading; final Widget? leading;
@ -27,7 +27,8 @@ class AdaptiveListTile extends HookWidget {
return ListTile( return ListTile(
title: title, title: title,
subtitle: subtitle, subtitle: subtitle,
trailing: breakpoint.isLessThan(breakOn) ? null : trailing, trailing:
breakpoint.isLessThan(breakOn) ? null : trailing?.call(context, null),
leading: leading, leading: leading,
onTap: breakpoint.isLessThan(breakOn) onTap: breakpoint.isLessThan(breakOn)
? () { ? () {
@ -35,20 +36,22 @@ class AdaptiveListTile extends HookWidget {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return StatefulBuilder(builder: (context, update) {
title: title != null return AlertDialog(
? Row( title: title != null
children: [ ? Row(
if (leading != null) ...[ children: [
leading!, if (leading != null) ...[
const SizedBox(width: 5) leading!,
const SizedBox(width: 5)
],
Flexible(child: title!),
], ],
Flexible(child: title!), )
], : null,
) content: trailing?.call(context, update),
: null, );
content: trailing, });
);
}, },
); );
} }