2022-10-19 18:34:11 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/screens/settings/section_label.dart';
|
|
|
|
import 'package:adguard_home_manager/widgets/custom_radio_list_tile.dart';
|
|
|
|
|
2022-10-19 20:26:40 +02:00
|
|
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
|
|
|
|
2022-10-19 18:34:11 +02:00
|
|
|
class UpstreamDnsScreen extends StatefulWidget {
|
2022-10-19 20:26:40 +02:00
|
|
|
final ServersProvider serversProvider;
|
|
|
|
|
|
|
|
const UpstreamDnsScreen({
|
|
|
|
Key? key,
|
|
|
|
required this.serversProvider,
|
|
|
|
}) : super(key: key);
|
2022-10-19 18:34:11 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<UpstreamDnsScreen> createState() => _UpstreamDnsScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
|
2022-10-19 20:26:40 +02:00
|
|
|
List<TextEditingController> upstreamControllers = [];
|
2022-10-19 18:34:11 +02:00
|
|
|
|
2022-10-19 21:57:48 +02:00
|
|
|
String upstreamMode = "";
|
|
|
|
|
|
|
|
bool validValues = false;
|
|
|
|
|
|
|
|
checkValidValues() {
|
|
|
|
if (
|
|
|
|
upstreamControllers.isNotEmpty &&
|
|
|
|
upstreamControllers.every((element) => element.text != '')
|
|
|
|
) {
|
|
|
|
setState(() => validValues = true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setState(() => validValues = false);
|
|
|
|
}
|
|
|
|
}
|
2022-10-19 18:34:11 +02:00
|
|
|
|
2022-10-19 20:26:40 +02:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
for (var item in widget.serversProvider.dnsInfo.data!.upstreamDns) {
|
|
|
|
final controller = TextEditingController();
|
|
|
|
controller.text = item;
|
|
|
|
upstreamControllers.add(controller);
|
|
|
|
}
|
|
|
|
upstreamMode = widget.serversProvider.dnsInfo.data!.upstreamMode;
|
2022-10-19 21:57:48 +02:00
|
|
|
validValues = true;
|
2022-10-19 20:26:40 +02:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-10-19 18:34:11 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.upstreamDns),
|
2022-10-19 21:57:48 +02:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: validValues == true
|
|
|
|
? () => {}
|
|
|
|
: null,
|
|
|
|
icon: const Icon(Icons.save_rounded),
|
|
|
|
tooltip: AppLocalizations.of(context)!.save,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10)
|
|
|
|
],
|
2022-10-19 18:34:11 +02:00
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
children: [
|
|
|
|
if (upstreamControllers.isEmpty) Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.noUpstreamDns,
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.grey,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
...upstreamControllers.map((c) => Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 24, right: 10, bottom: 20
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width-90,
|
|
|
|
child: TextFormField(
|
|
|
|
controller: c,
|
2022-10-19 21:57:48 +02:00
|
|
|
onChanged: (_) => checkValidValues(),
|
2022-10-19 18:34:11 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.dns_rounded),
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
labelText: AppLocalizations.of(context)!.dnsServer,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
2022-10-19 21:57:48 +02:00
|
|
|
onPressed: () {
|
|
|
|
setState(() => upstreamControllers = upstreamControllers.where((con) => con != c).toList());
|
|
|
|
checkValidValues();
|
|
|
|
},
|
2022-10-19 18:34:11 +02:00
|
|
|
icon: const Icon(Icons.remove_circle_outline)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)).toList(),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
ElevatedButton.icon(
|
2022-10-19 21:57:48 +02:00
|
|
|
onPressed: () {
|
|
|
|
setState(() => upstreamControllers.add(TextEditingController()));
|
|
|
|
checkValidValues();
|
|
|
|
},
|
2022-10-19 18:34:11 +02:00
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
label: Text(AppLocalizations.of(context)!.addItem)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SectionLabel(label: AppLocalizations.of(context)!.dnsMode),
|
|
|
|
CustomRadioListTile(
|
|
|
|
groupValue: upstreamMode,
|
2022-10-19 20:26:40 +02:00
|
|
|
value: "",
|
2022-10-19 18:34:11 +02:00
|
|
|
radioBackgroundColor: Theme.of(context).dialogBackgroundColor,
|
|
|
|
title: AppLocalizations.of(context)!.loadBalancing,
|
|
|
|
subtitle: AppLocalizations.of(context)!.loadBalancingDescription,
|
|
|
|
onChanged: (value) => setState(() => upstreamMode = value),
|
|
|
|
),
|
|
|
|
CustomRadioListTile(
|
|
|
|
groupValue: upstreamMode,
|
2022-10-19 20:26:40 +02:00
|
|
|
value: "parallel",
|
2022-10-19 18:34:11 +02:00
|
|
|
radioBackgroundColor: Theme.of(context).dialogBackgroundColor,
|
|
|
|
title: AppLocalizations.of(context)!.parallelRequests,
|
|
|
|
subtitle: AppLocalizations.of(context)!.parallelRequestsDescription,
|
|
|
|
onChanged: (value) => setState(() => upstreamMode = value),
|
|
|
|
),
|
|
|
|
CustomRadioListTile(
|
|
|
|
groupValue: upstreamMode,
|
2022-10-19 20:26:40 +02:00
|
|
|
value: "fastest_addr",
|
2022-10-19 18:34:11 +02:00
|
|
|
radioBackgroundColor: Theme.of(context).dialogBackgroundColor,
|
|
|
|
title: AppLocalizations.of(context)!.fastestIpAddress,
|
|
|
|
subtitle: AppLocalizations.of(context)!.fastestIpAddressDescription,
|
|
|
|
onChanged: (value) => setState(() => upstreamMode = value),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|