From 7a89aea3a59540c9e7ad92ac93f650702698bc18 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Wed, 21 Feb 2024 10:50:02 +0100 Subject: [PATCH] Changed dns addresses modal --- .../server_info/dns_addresses_modal.dart | 93 +++++++++++-------- .../settings/server_info/server_info.dart | 27 ++++-- 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/lib/screens/settings/server_info/dns_addresses_modal.dart b/lib/screens/settings/server_info/dns_addresses_modal.dart index 2a6fa2f..e5fb87a 100644 --- a/lib/screens/settings/server_info/dns_addresses_modal.dart +++ b/lib/screens/settings/server_info/dns_addresses_modal.dart @@ -1,54 +1,71 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; +import 'package:adguard_home_manager/widgets/list_bottom_sheet.dart'; + class DnsAddressesModal extends StatelessWidget { + final bool isDialog; final List dnsAddresses; const DnsAddressesModal({ - Key? key, + super.key, + required this.isDialog, required this.dnsAddresses, - }) : super(key: key); + }); @override Widget build(BuildContext context) { - return AlertDialog( - title: Column( - children: [ - Icon( - Icons.route_rounded, - color: Theme.of(context).listTileTheme.iconColor - ), - const SizedBox(height: 16), - Text( - AppLocalizations.of(context)!.dnsAddresses, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface + if (isDialog == true) { + return AlertDialog( + title: Column( + children: [ + Icon( + Icons.route_rounded, + color: Theme.of(context).listTileTheme.iconColor ), + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.dnsAddresses, + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface + ), + ) + ], + ), + content: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 500), + child: SingleChildScrollView( + child: Wrap( + children: dnsAddresses.map((address) => ListTile( + title: Text( + address, + style: TextStyle( + fontWeight: FontWeight.normal, + color: Theme.of(context).listTileTheme.textColor + ), + ), + )).toList(), + ), + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: Text(AppLocalizations.of(context)!.close) ) ], - ), - content: SizedBox( - height: dnsAddresses.length*56 < 500 - ? dnsAddresses.length*56 : 500, - width: double.minPositive, - child: ListView( - children: dnsAddresses.map((address) => ListTile( - title: Text( - address, - style: TextStyle( - fontWeight: FontWeight.normal, - color: Theme.of(context).listTileTheme.textColor - ), - ), - )).toList(), - ), - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: Text(AppLocalizations.of(context)!.close) - ) - ], - ); + ); + } + else { + return ListBottomSheet( + icon: Icons.route_rounded, + title: AppLocalizations.of(context)!.dnsAddresses, + children: dnsAddresses.map((address) => CustomListTile( + title: address, + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), + )).toList(), + ); + } } } \ No newline at end of file diff --git a/lib/screens/settings/server_info/server_info.dart b/lib/screens/settings/server_info/server_info.dart index b15d8e0..85de4f6 100644 --- a/lib/screens/settings/server_info/server_info.dart +++ b/lib/screens/settings/server_info/server_info.dart @@ -86,12 +86,27 @@ class _ServerInformationState extends State { title: AppLocalizations.of(context)!.dnsAddresses, subtitle: AppLocalizations.of(context)!.seeDnsAddresses, onTap: () { - showModal( - context: context, - builder: (context) => DnsAddressesModal( - dnsAddresses: serverInfo.data!.dnsAddresses - ) - ); + if (width > 700) { + showDialog( + context: context, + builder: (context) => DnsAddressesModal( + dnsAddresses: serverInfo.data!.dnsAddresses, + isDialog: true, + ) + ); + } + else { + showModalBottomSheet( + context: context, + builder: (context) => DnsAddressesModal( + dnsAddresses: serverInfo.data!.dnsAddresses, + isDialog: false, + ), + isScrollControlled: true, + backgroundColor: Colors.transparent, + useSafeArea: true + ); + } }, ), CustomListTile(