Fixed duplicated snackbar desktop

This commit is contained in:
Juan Gilsanz Polo 2024-01-29 15:04:52 +01:00
parent a4e8694cc1
commit 02b9bd034f
3 changed files with 223 additions and 228 deletions

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:adguard_home_manager/config/globals.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_svg/flutter_svg.dart';
@ -101,214 +102,217 @@ class _SettingsWidgetState extends State<_SettingsWidget> {
appConfigProvider.setSelectedSettingsScreen(screen: null);
}
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar.large(
pinned: true,
floating: true,
centerTitle: false,
forceElevated: innerBoxIsScrolled,
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
title: Text(AppLocalizations.of(context)!.settings),
return ScaffoldMessenger(
key: widget.twoColumns ? GlobalKey() : null,
child: Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar.large(
pinned: true,
floating: true,
centerTitle: false,
forceElevated: innerBoxIsScrolled,
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
title: Text(AppLocalizations.of(context)!.settings),
)
)
)
],
body: SafeArea(
top: false,
bottom: false,
child: Builder(
builder: (context) => CustomScrollView(
slivers: [
SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
SliverList.list(
children: [
if (
serversProvider.selectedServer != null &&
statusProvider.serverStatus != null &&
serversProvider.apiClient2 != null
) ...[
SectionLabel(label: AppLocalizations.of(context)!.serverSettings),
_SettingsTile(
icon: Icons.search_rounded,
title: AppLocalizations.of(context)!.safeSearch,
subtitle: AppLocalizations.of(context)!.safeSearchSettings,
thisItem: 0,
screenToNavigate: const SafeSearchSettingsScreen(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.list_alt_rounded,
title: AppLocalizations.of(context)!.logsSettings,
subtitle: AppLocalizations.of(context)!.logsSettingsDescription,
thisItem: 1,
screenToNavigate: const LogsSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.analytics_rounded,
title: AppLocalizations.of(context)!.statisticsSettings,
subtitle: AppLocalizations.of(context)!.statisticsSettingsDescription,
thisItem: 2,
screenToNavigate: const StatisticsSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.lock_rounded,
title: AppLocalizations.of(context)!.accessSettings,
subtitle: AppLocalizations.of(context)!.accessSettingsDescription,
thisItem: 3,
screenToNavigate: const AccessSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.install_desktop_rounded,
title: AppLocalizations.of(context)!.dhcpSettings,
subtitle: AppLocalizations.of(context)!.dhcpSettingsDescription,
thisItem: 4,
screenToNavigate: const DhcpScreen(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.dns_rounded,
title: AppLocalizations.of(context)!.dnsSettings,
subtitle: AppLocalizations.of(context)!.dnsSettingsDescription,
thisItem: 5,
screenToNavigate: DnsSettings(
splitView: widget.twoColumns,
],
body: SafeArea(
top: false,
bottom: false,
child: Builder(
builder: (context) => CustomScrollView(
slivers: [
SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
SliverList.list(
children: [
if (
serversProvider.selectedServer != null &&
statusProvider.serverStatus != null &&
serversProvider.apiClient2 != null
) ...[
SectionLabel(label: AppLocalizations.of(context)!.serverSettings),
_SettingsTile(
icon: Icons.search_rounded,
title: AppLocalizations.of(context)!.safeSearch,
subtitle: AppLocalizations.of(context)!.safeSearchSettings,
thisItem: 0,
screenToNavigate: const SafeSearchSettingsScreen(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.list_alt_rounded,
title: AppLocalizations.of(context)!.logsSettings,
subtitle: AppLocalizations.of(context)!.logsSettingsDescription,
thisItem: 1,
screenToNavigate: const LogsSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.analytics_rounded,
title: AppLocalizations.of(context)!.statisticsSettings,
subtitle: AppLocalizations.of(context)!.statisticsSettingsDescription,
thisItem: 2,
screenToNavigate: const StatisticsSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.lock_rounded,
title: AppLocalizations.of(context)!.accessSettings,
subtitle: AppLocalizations.of(context)!.accessSettingsDescription,
thisItem: 3,
screenToNavigate: const AccessSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.install_desktop_rounded,
title: AppLocalizations.of(context)!.dhcpSettings,
subtitle: AppLocalizations.of(context)!.dhcpSettingsDescription,
thisItem: 4,
screenToNavigate: const DhcpScreen(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.dns_rounded,
title: AppLocalizations.of(context)!.dnsSettings,
subtitle: AppLocalizations.of(context)!.dnsSettingsDescription,
thisItem: 5,
screenToNavigate: DnsSettings(
splitView: widget.twoColumns,
),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.security_rounded,
title: AppLocalizations.of(context)!.encryptionSettings,
subtitle: AppLocalizations.of(context)!.encryptionSettingsDescription,
thisItem: 6,
screenToNavigate: const EncryptionSettings(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.route_rounded,
title: AppLocalizations.of(context)!.dnsRewrites,
subtitle: AppLocalizations.of(context)!.dnsRewritesDescription,
thisItem: 7,
screenToNavigate: const DnsRewritesScreen(),
twoColumns: widget.twoColumns,
),
if (serversProvider.updateAvailable.data != null) _SettingsTile(
icon: Icons.system_update_rounded,
title: AppLocalizations.of(context)!.updates,
subtitle: AppLocalizations.of(context)!.updatesDescription,
trailing: serversProvider.updateAvailable.data != null &&
serversProvider.updateAvailable.data!.canAutoupdate == true
? Container(
width: 10,
height: 10,
margin: const EdgeInsets.only(right: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red
),
)
: null,
thisItem: 8,
screenToNavigate: const UpdateScreen(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.info_rounded,
title: AppLocalizations.of(context)!.serverInformation,
subtitle: AppLocalizations.of(context)!.serverInformationDescription,
thisItem: 9,
screenToNavigate: const ServerInformation(),
twoColumns: widget.twoColumns,
),
],
SectionLabel(label: AppLocalizations.of(context)!.appSettings),
_SettingsTile(
icon: Icons.palette_rounded,
title: AppLocalizations.of(context)!.customization,
subtitle: AppLocalizations.of(context)!.customizationDescription,
thisItem: 10,
screenToNavigate: const Customization(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.security_rounded,
title: AppLocalizations.of(context)!.encryptionSettings,
subtitle: AppLocalizations.of(context)!.encryptionSettingsDescription,
thisItem: 6,
screenToNavigate: const EncryptionSettings(),
icon: Icons.storage_rounded,
title: AppLocalizations.of(context)!.servers,
subtitle: serversProvider.selectedServer != null
? statusProvider.serverStatus != null
? "${AppLocalizations.of(context)!.connectedTo} ${serversProvider.selectedServer!.name}"
: "${AppLocalizations.of(context)!.selectedServer} ${serversProvider.selectedServer!.name}"
: AppLocalizations.of(context)!.noServerSelected,
thisItem: 11,
screenToNavigate: const Servers(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.route_rounded,
title: AppLocalizations.of(context)!.dnsRewrites,
subtitle: AppLocalizations.of(context)!.dnsRewritesDescription,
thisItem: 7,
screenToNavigate: const DnsRewritesScreen(),
twoColumns: widget.twoColumns,
),
if (serversProvider.updateAvailable.data != null) _SettingsTile(
icon: Icons.system_update_rounded,
title: AppLocalizations.of(context)!.updates,
subtitle: AppLocalizations.of(context)!.updatesDescription,
trailing: serversProvider.updateAvailable.data != null &&
serversProvider.updateAvailable.data!.canAutoupdate == true
? Container(
width: 10,
height: 10,
margin: const EdgeInsets.only(right: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red
),
)
: null,
thisItem: 8,
screenToNavigate: const UpdateScreen(),
icon: Icons.settings,
title: AppLocalizations.of(context)!.generalSettings,
subtitle: AppLocalizations.of(context)!.generalSettingsDescription,
thisItem: 12,
screenToNavigate: GeneralSettings(splitView: widget.twoColumns),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.info_rounded,
title: AppLocalizations.of(context)!.serverInformation,
subtitle: AppLocalizations.of(context)!.serverInformationDescription,
thisItem: 9,
screenToNavigate: const ServerInformation(),
icon: Icons.build_outlined,
title: AppLocalizations.of(context)!.advancedSettings,
subtitle: AppLocalizations.of(context)!.advancedSetupDescription,
thisItem: 13,
screenToNavigate: const AdvancedSettings(),
twoColumns: widget.twoColumns,
),
SectionLabel(label: AppLocalizations.of(context)!.aboutApp),
CustomListTile(
title: AppLocalizations.of(context)!.appVersion,
subtitle: appConfigProvider.getAppInfo!.version,
),
CustomListTile(
title: AppLocalizations.of(context)!.createdBy,
subtitle: Strings.createdBy,
),
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (Platform.isAndroid) IconButton(
onPressed: () => openUrl(Urls.playStore),
icon: SvgPicture.asset(
'assets/resources/google-play.svg',
color: Theme.of(context).colorScheme.onSurfaceVariant,
width: 30,
height: 30,
),
tooltip: AppLocalizations.of(context)!.visitGooglePlay,
),
IconButton(
onPressed: () => openUrl(Urls.gitHub),
icon: SvgPicture.asset(
'assets/resources/github.svg',
color: Theme.of(context).colorScheme.onSurfaceVariant,
width: 30,
height: 30,
),
tooltip: AppLocalizations.of(context)!.gitHub,
),
],
),
)
],
SectionLabel(label: AppLocalizations.of(context)!.appSettings),
_SettingsTile(
icon: Icons.palette_rounded,
title: AppLocalizations.of(context)!.customization,
subtitle: AppLocalizations.of(context)!.customizationDescription,
thisItem: 10,
screenToNavigate: const Customization(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.storage_rounded,
title: AppLocalizations.of(context)!.servers,
subtitle: serversProvider.selectedServer != null
? statusProvider.serverStatus != null
? "${AppLocalizations.of(context)!.connectedTo} ${serversProvider.selectedServer!.name}"
: "${AppLocalizations.of(context)!.selectedServer} ${serversProvider.selectedServer!.name}"
: AppLocalizations.of(context)!.noServerSelected,
thisItem: 11,
screenToNavigate: const Servers(),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.settings,
title: AppLocalizations.of(context)!.generalSettings,
subtitle: AppLocalizations.of(context)!.generalSettingsDescription,
thisItem: 12,
screenToNavigate: GeneralSettings(splitView: widget.twoColumns),
twoColumns: widget.twoColumns,
),
_SettingsTile(
icon: Icons.build_outlined,
title: AppLocalizations.of(context)!.advancedSettings,
subtitle: AppLocalizations.of(context)!.advancedSetupDescription,
thisItem: 13,
screenToNavigate: const AdvancedSettings(),
twoColumns: widget.twoColumns,
),
SectionLabel(label: AppLocalizations.of(context)!.aboutApp),
CustomListTile(
title: AppLocalizations.of(context)!.appVersion,
subtitle: appConfigProvider.getAppInfo!.version,
),
CustomListTile(
title: AppLocalizations.of(context)!.createdBy,
subtitle: Strings.createdBy,
),
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (Platform.isAndroid) IconButton(
onPressed: () => openUrl(Urls.playStore),
icon: SvgPicture.asset(
'assets/resources/google-play.svg',
color: Theme.of(context).colorScheme.onSurfaceVariant,
width: 30,
height: 30,
),
tooltip: AppLocalizations.of(context)!.visitGooglePlay,
),
IconButton(
onPressed: () => openUrl(Urls.gitHub),
icon: SvgPicture.asset(
'assets/resources/github.svg',
color: Theme.of(context).colorScheme.onSurfaceVariant,
width: 30,
height: 30,
),
tooltip: AppLocalizations.of(context)!.gitHub,
),
],
),
)
],
)
],
)
)
],
)
),
),
),
)
)
),
);
}
}