Skip to content

Commit

Permalink
タブ設定で利用できない種類のタブを作成できないように
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Jan 3, 2024
1 parent d3aa4de commit 7ff7d36
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/view/settings_page/tab_settings_page/tab_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class TabSettingsAddDialogState extends ConsumerState<TabSettingsPage> {
selectedTabType == TabType.localTimeline ||
selectedTabType == TabType.hybridTimeline;

bool isTabTypeAvailable(TabType tabType) {
return switch (tabType) {
TabType.localTimeline =>
selectedAccount?.i.policies.ltlAvailable ?? false,
TabType.globalTimeline =>
selectedAccount?.i.policies.gtlAvailable ?? false,
_ => true,
};
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand Down Expand Up @@ -156,8 +166,13 @@ class TabSettingsAddDialogState extends ConsumerState<TabSettingsPage> {
),
],
onChanged: (value) {
final tabType = selectedTabType;
setState(() {
selectedAccount = value;
selectedTabType =
tabType != null && isTabTypeAvailable(tabType)
? tabType
: null;
selectedAntenna = null;
selectedUserList = null;
selectedChannel = null;
Expand All @@ -173,10 +188,11 @@ class TabSettingsAddDialogState extends ConsumerState<TabSettingsPage> {
DropdownButton<TabType>(
items: [
for (final tabType in TabType.values)
DropdownMenuItem(
value: tabType,
child: Text(tabType.displayName),
),
if (isTabTypeAvailable(tabType))
DropdownMenuItem(
value: tabType,
child: Text(tabType.displayName),
),
],
onChanged: (value) {
setState(() {
Expand Down

0 comments on commit 7ff7d36

Please sign in to comment.