Skip to content

Commit

Permalink
fix(adaptive-list-tile): dialog content not updating when content has…
Browse files Browse the repository at this point in the history
… changed
  • Loading branch information
KRTirtho committed Aug 25, 2022
1 parent 307a8e2 commit a1d4230
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
27 changes: 18 additions & 9 deletions lib/components/Settings/Settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Settings extends HookConsumerWidget {
AdaptiveListTile(
leading: const Icon(Icons.dark_mode_outlined),
title: const Text("Theme"),
trailing: DropdownButton<ThemeMode>(
trailing: (context, update) => DropdownButton<ThemeMode>(
value: preferences.themeMode,
items: const [
DropdownMenuItem(
Expand All @@ -89,6 +89,7 @@ class Settings extends HookConsumerWidget {
onChanged: (value) {
if (value != null) {
preferences.setThemeMode(value);
update?.call(() {});
}
},
),
Expand Down Expand Up @@ -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,
Expand All @@ -149,6 +150,7 @@ class Settings extends HookConsumerWidget {
preferences.setRecommendationMarket(
value as String,
);
update?.call(() {});
},
),
),
Expand All @@ -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,
Expand All @@ -188,6 +190,7 @@ class Settings extends HookConsumerWidget {
),
onSubmitted: (value) {
preferences.setYtSearchFormat(value);
update?.call(() {});
},
),
),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -258,7 +261,8 @@ class Settings extends HookConsumerWidget {
"Track Match Algorithm",
maxLines: 1,
),
trailing: DropdownButton<SpotubeTrackMatchAlgorithm>(
trailing: (context, update) =>
DropdownButton<SpotubeTrackMatchAlgorithm>(
value: preferences.trackMatchAlgorithm,
items: const [
DropdownMenuItem(
Expand All @@ -281,14 +285,16 @@ class Settings extends HookConsumerWidget {
onChanged: (value) {
if (value != null) {
preferences.setTrackMatchAlgorithm(value);
update?.call(() {});
}
},
),
),
AdaptiveListTile(
leading: const Icon(Icons.multitrack_audio_rounded),
title: const Text("Audio Quality"),
trailing: DropdownButton<AudioQuality>(
trailing: (context, update) =>
DropdownButton<AudioQuality>(
value: preferences.audioQuality,
items: const [
DropdownMenuItem(
Expand All @@ -305,6 +311,7 @@ class Settings extends HookConsumerWidget {
onChanged: (value) {
if (value != null) {
preferences.setAudioQuality(value);
update?.call(() {});
}
},
),
Expand Down Expand Up @@ -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(
Expand All @@ -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,
);
},
),
),
Expand Down
33 changes: 18 additions & 15 deletions lib/components/Shared/AdaptiveListTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,28 +27,31 @@ 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)
? () {
onTap?.call();
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),
);
});
},
);
}
Expand Down

0 comments on commit a1d4230

Please sign in to comment.