More improvements

This commit is contained in:
Juan Gilsanz Polo 2023-05-01 03:48:23 +02:00
parent 5d23f3c3e7
commit 129a77d979
4 changed files with 247 additions and 146 deletions

View file

@ -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<DhcpWidget> {
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<DhcpWidget> {
)
),
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),

View file

@ -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<CommentModal> {
@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()
),
);
}
}
}

View file

@ -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<DnsSettingsWidget> {
final serversProvider = Provider.of<ServersProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(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<DnsSettingsWidget> {
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,
),
],

View file

@ -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<UpstreamDnsScreen> {
Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(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<String, dynamic> 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 {