From 129a77d979cbe6e782d3a3f2e42a2080cb89bb4d Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Mon, 1 May 2023 03:48:23 +0200 Subject: [PATCH] More improvements --- lib/screens/settings/dhcp/dhcp.dart | 50 +++-- lib/screens/settings/dns/comment_modal.dart | 210 +++++++++++--------- lib/screens/settings/dns/dns.dart | 44 ++-- lib/screens/settings/dns/upstream_dns.dart | 89 ++++++--- 4 files changed, 247 insertions(+), 146 deletions(-) diff --git a/lib/screens/settings/dhcp/dhcp.dart b/lib/screens/settings/dhcp/dhcp.dart index b48245f..461fd73 100644 --- a/lib/screens/settings/dhcp/dhcp.dart +++ b/lib/screens/settings/dhcp/dhcp.dart @@ -3,8 +3,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:flutter_split_view/flutter_split_view.dart'; import 'package:provider/provider.dart'; -import 'package:bottom_sheet/bottom_sheet.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:adguard_home_manager/widgets/section_label.dart'; @@ -752,12 +752,24 @@ class _DhcpWidgetState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( - onPressed: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => DhcpLeases( - items: serversProvider.dhcp.data!.dhcpStatus.leases, - staticLeases: false, - ) - )), + onPressed: () { + if (!(Platform.isAndroid || Platform.isIOS)) { + SplitView.of(context).push( + DhcpLeases( + items: serversProvider.dhcp.data!.dhcpStatus.leases, + staticLeases: false, + ) + ); + } + else { + Navigator.push(context, MaterialPageRoute( + builder: (context) => DhcpLeases( + items: serversProvider.dhcp.data!.dhcpStatus.leases, + staticLeases: false, + ) + )); + } + }, child: Row( children: [ Text(AppLocalizations.of(context)!.dhcpLeases), @@ -767,12 +779,24 @@ class _DhcpWidgetState extends State { ) ), ElevatedButton( - onPressed: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => DhcpLeases( - items: serversProvider.dhcp.data!.dhcpStatus.staticLeases, - staticLeases: true, - ) - )), + onPressed: () { + if (!(Platform.isAndroid || Platform.isIOS)) { + SplitView.of(context).push( + DhcpLeases( + items: serversProvider.dhcp.data!.dhcpStatus.staticLeases, + staticLeases: true, + ) + ); + } + else { + Navigator.push(context, MaterialPageRoute( + builder: (context) => DhcpLeases( + items: serversProvider.dhcp.data!.dhcpStatus.staticLeases, + staticLeases: true, + ) + )); + } + }, child: Row( children: [ Text(AppLocalizations.of(context)!.dhcpStatic), diff --git a/lib/screens/settings/dns/comment_modal.dart b/lib/screens/settings/dns/comment_modal.dart index 20ad859..51f5395 100644 --- a/lib/screens/settings/dns/comment_modal.dart +++ b/lib/screens/settings/dns/comment_modal.dart @@ -4,11 +4,13 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class CommentModal extends StatefulWidget { final String? comment; final void Function(String) onConfirm; + final bool dialog; const CommentModal({ Key? key, this.comment, - required this.onConfirm + required this.onConfirm, + required this.dialog }) : super(key: key); @override @@ -30,103 +32,125 @@ class _CommentModalState extends State { @override Widget build(BuildContext context) { - return Padding( - padding: MediaQuery.of(context).viewInsets, - child: Container( - height: 310, - decoration: BoxDecoration( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(28), - topRight: Radius.circular(28) - ), - color: Theme.of(context).dialogBackgroundColor - ), - child: Column( - children: [ - Expanded( - child: ListView( - physics: MediaQuery.of(context).size.height >= 330 == true - ? const NeverScrollableScrollPhysics() - : null, - children: [ - Padding( - padding: const EdgeInsets.only(top: 24), - child: Icon( - Icons.comment_rounded, - size: 24, - color: Theme.of(context).colorScheme.secondary, - ), - ), - const SizedBox(height: 16), - Text( - AppLocalizations.of(context)!.comment, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 24, - color: Theme.of(context).colorScheme.onSurface - ), - ), - const SizedBox(height: 16), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: TextFormField( - controller: commentController, - onChanged: (value) { - if (value != '') { - setState(() => validData = true); - } - else { - setState(() => validData = false); - } - }, - decoration: InputDecoration( - prefixIcon: const Icon(Icons.comment_rounded), - border: const OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(10) - ) + Widget content() { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + SingleChildScrollView( + child: Wrap( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column( + children: [ + Padding( + padding: const EdgeInsets.only(top: 24), + child: Icon( + Icons.comment_rounded, + size: 24, + color: Theme.of(context).colorScheme.secondary, + ), ), - labelText: AppLocalizations.of(context)!.comment, - helperText: AppLocalizations.of(context)!.commentsDescription, - helperMaxLines: 3 - ) + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.comment, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 24, + color: Theme.of(context).colorScheme.onSurface + ), + ), + const SizedBox(height: 16), + ], ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.all(24), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: Text(AppLocalizations.of(context)!.cancel) - ), - const SizedBox(width: 20), - TextButton( - onPressed: validData == true - ? () { - Navigator.pop(context); - widget.onConfirm("# ${commentController.text}"); - } - : null, - child: Text( - AppLocalizations.of(context)!.confirm, - style: TextStyle( - color: validData == true - ? Theme.of(context).colorScheme.primary - : Colors.grey + ], + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 24), + child: TextFormField( + controller: commentController, + onChanged: (value) { + if (value != '') { + setState(() => validData = true); + } + else { + setState(() => validData = false); + } + }, + decoration: InputDecoration( + prefixIcon: const Icon(Icons.comment_rounded), + border: const OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(10) + ) ), + labelText: AppLocalizations.of(context)!.comment, + helperText: AppLocalizations.of(context)!.commentsDescription, + helperMaxLines: 3 ) ), - ], - ), - ) - ], + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.all(24), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: Text(AppLocalizations.of(context)!.cancel) + ), + const SizedBox(width: 20), + TextButton( + onPressed: validData == true + ? () { + Navigator.pop(context); + widget.onConfirm("# ${commentController.text}"); + } + : null, + child: Text( + AppLocalizations.of(context)!.confirm, + style: TextStyle( + color: validData == true + ? Theme.of(context).colorScheme.primary + : Colors.grey + ), + ) + ), + ], + ), + ) + ], + ); + } + + if (widget.dialog == true) { + return Dialog( + child: ConstrainedBox( + constraints: const BoxConstraints( + maxWidth: 400 + ), + child: content() ), - ), - ); + ); + } + else { + return Padding( + padding: MediaQuery.of(context).viewInsets, + child: Container( + decoration: BoxDecoration( + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(28), + topRight: Radius.circular(28) + ), + color: Theme.of(context).dialogBackgroundColor + ), + child: content() + ), + ); + } } } \ No newline at end of file diff --git a/lib/screens/settings/dns/dns.dart b/lib/screens/settings/dns/dns.dart index 229c167..63982b1 100644 --- a/lib/screens/settings/dns/dns.dart +++ b/lib/screens/settings/dns/dns.dart @@ -1,6 +1,9 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:flutter_split_view/flutter_split_view.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -76,6 +79,17 @@ class _DnsSettingsWidgetState extends State { final serversProvider = Provider.of(context); final appConfigProvider = Provider.of(context); + void navigate(Widget widget) { + if (!(Platform.isAndroid || Platform.isIOS)) { + SplitView.of(context).push(widget); + } + else { + Navigator.push(context, MaterialPageRoute( + builder: (context) => widget + )); + } + } + Widget generateBody() { switch (widget.serversProvider.dnsInfo.loadStatus) { case 0: @@ -105,51 +119,51 @@ class _DnsSettingsWidgetState extends State { CustomListTile( title: AppLocalizations.of(context)!.upstreamDns, subtitle: AppLocalizations.of(context)!.upstreamDnsDescription, - onTap: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => UpstreamDnsScreen( + onTap: () => navigate( + UpstreamDnsScreen( serversProvider: serversProvider ) - )), + ), icon: Icons.upload_rounded, ), CustomListTile( title: AppLocalizations.of(context)!.bootstrapDns, subtitle: AppLocalizations.of(context)!.bootstrapDnsDescription, - onTap: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => BootstrapDnsScreen( + onTap: () => navigate( + BootstrapDnsScreen( serversProvider: serversProvider ) - )), + ), icon: Icons.dns_rounded, ), CustomListTile( title: AppLocalizations.of(context)!.privateReverseDnsServers, subtitle: AppLocalizations.of(context)!.privateReverseDnsDescription, - onTap: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => PrivateReverseDnsServersScreen( + onTap: () => navigate( + PrivateReverseDnsServersScreen( serversProvider: serversProvider ) - )), + ), icon: Icons.person_rounded, ), CustomListTile( title: AppLocalizations.of(context)!.dnsServerSettings, subtitle: AppLocalizations.of(context)!.dnsServerSettingsDescription, - onTap: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => DnsServerSettingsScreen( + onTap: () => navigate( + DnsServerSettingsScreen( serversProvider: serversProvider ) - )), + ), icon: Icons.settings, ), CustomListTile( title: AppLocalizations.of(context)!.dnsCacheConfig, subtitle: AppLocalizations.of(context)!.dnsCacheConfigDescription, - onTap: () => Navigator.push(context, MaterialPageRoute( - builder: (context) => CacheConfigDnsScreen( + onTap: () => navigate( + CacheConfigDnsScreen( serversProvider: serversProvider ) - )), + ), icon: Icons.storage_rounded, ), ], diff --git a/lib/screens/settings/dns/upstream_dns.dart b/lib/screens/settings/dns/upstream_dns.dart index f32983f..66d8b8c 100644 --- a/lib/screens/settings/dns/upstream_dns.dart +++ b/lib/screens/settings/dns/upstream_dns.dart @@ -1,5 +1,7 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -71,36 +73,73 @@ class _UpstreamDnsScreenState extends State { Widget build(BuildContext context) { final serversProvider = Provider.of(context); final appConfigProvider = Provider.of(context); + + final width = MediaQuery.of(context).size.width; void openAddCommentModal() { - showModalBottomSheet( - context: context, - builder: (context) => CommentModal( - onConfirm: (value) { - dnsServers.add({ - 'comment': value - }); - }, - ), - backgroundColor: Colors.transparent, - isScrollControlled: true, - isDismissible: true - ); + if (width > 900 || !(Platform.isAndroid || Platform.isIOS)) { + showDialog( + context: context, + builder: (context) => CommentModal( + onConfirm: (value) { + setState(() { + dnsServers.add({ + 'comment': value + }); + }); + }, + dialog: true, + ), + ); + } + else { + showModalBottomSheet( + context: context, + builder: (context) => CommentModal( + onConfirm: (value) { + setState(() { + dnsServers.add({ + 'comment': value + }); + }); + }, + dialog: false, + ), + backgroundColor: Colors.transparent, + isScrollControlled: true, + isDismissible: true + ); + } } void openEditCommentModal(Map item, int position) { - showModalBottomSheet( - context: context, - builder: (context) => CommentModal( - comment: item['comment'], - onConfirm: (value) { - setState(() => dnsServers[position] = { 'comment': value }); - }, - ), - backgroundColor: Colors.transparent, - isScrollControlled: true, - isDismissible: true - ); + if (width > 900 || !(Platform.isAndroid || Platform.isIOS)) { + showDialog( + context: context, + builder: (context) => CommentModal( + comment: item['comment'], + onConfirm: (value) { + setState(() => dnsServers[position] = { 'comment': value }); + }, + dialog: true, + ), + ); + } + else { + showModalBottomSheet( + context: context, + builder: (context) => CommentModal( + comment: item['comment'], + onConfirm: (value) { + setState(() => dnsServers[position] = { 'comment': value }); + }, + dialog: false, + ), + backgroundColor: Colors.transparent, + isScrollControlled: true, + isDismissible: true + ); + } } void saveData() async {