mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-16 15:02:53 +00:00
Added server info screen
This commit is contained in:
parent
da14ed6bd7
commit
c78ae81122
8 changed files with 368 additions and 3 deletions
40
lib/screens/settings/dns_addresses_modal.dart
Normal file
40
lib/screens/settings/dns_addresses_modal.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class DnsAddressesModal extends StatelessWidget {
|
||||
final List<String> dnsAddresses;
|
||||
|
||||
const DnsAddressesModal({
|
||||
Key? key,
|
||||
required this.dnsAddresses,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
const Icon(Icons.route_rounded),
|
||||
const SizedBox(height: 20),
|
||||
Text(AppLocalizations.of(context)!.dnsAddresses)
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
height: dnsAddresses.length*56 < 500
|
||||
? dnsAddresses.length*56 : 500,
|
||||
width: double.minPositive,
|
||||
child: ListView(
|
||||
children: dnsAddresses.map((address) => ListTile(
|
||||
title: Text(address),
|
||||
)).toList(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
184
lib/screens/settings/server_info.dart
Normal file
184
lib/screens/settings/server_info.dart
Normal file
|
@ -0,0 +1,184 @@
|
|||
import 'package:animations/animations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/dns_addresses_modal.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||
import 'package:adguard_home_manager/models/server_info.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
|
||||
class ServerInformation extends StatelessWidget {
|
||||
const ServerInformation({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
return ServerInformationWidget(
|
||||
serversProvider: serversProvider,
|
||||
appConfigProvider: appConfigProvider,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerInformationWidget extends StatefulWidget {
|
||||
final ServersProvider serversProvider;
|
||||
final AppConfigProvider appConfigProvider;
|
||||
|
||||
const ServerInformationWidget({
|
||||
Key? key,
|
||||
required this.serversProvider,
|
||||
required this.appConfigProvider,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ServerInformationWidget> createState() => _ServerInformationWidgetState();
|
||||
}
|
||||
|
||||
class _ServerInformationWidgetState extends State<ServerInformationWidget> {
|
||||
ServerInfo serverInfo = ServerInfo(loadStatus: 0);
|
||||
|
||||
void fetchServerInfo() async {
|
||||
final result = await getServerInfo(server: widget.serversProvider.selectedServer!);
|
||||
if (mounted) {
|
||||
if (result['result'] == 'success') {
|
||||
setState(() {
|
||||
serverInfo.loadStatus = 1;
|
||||
serverInfo.data = result['data'];
|
||||
});
|
||||
}
|
||||
else {
|
||||
widget.appConfigProvider.addLog(result['log']);
|
||||
setState(() => serverInfo.loadStatus = 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
fetchServerInfo();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget generateBody() {
|
||||
switch (serverInfo.loadStatus) {
|
||||
case 0:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 30),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.loadingServerInfo,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
case 1:
|
||||
return ListView(
|
||||
children: [
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dnsAddresses,
|
||||
description: AppLocalizations.of(context)!.seeDnsAddresses,
|
||||
onTap: () {
|
||||
showModal(
|
||||
context: context,
|
||||
builder: (context) => DnsAddressesModal(
|
||||
dnsAddresses: serverInfo.data!.dnsAddresses
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dnsPort,
|
||||
description: serverInfo.data!.dnsPort.toString(),
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.httpPort,
|
||||
description: serverInfo.data!.httpPort.toString(),
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.protectionEnabled,
|
||||
description: serverInfo.data!.protectionEnabled == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dhcpAvailable,
|
||||
description: serverInfo.data!.dhcpAvailable == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverRunning,
|
||||
description: serverInfo.data!.running == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverVersion,
|
||||
description: serverInfo.data!.version,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverLanguage,
|
||||
description: serverInfo.data!.language,
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
case 2:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
size: 50,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.serverInfoNotLoaded,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.serverInformation),
|
||||
),
|
||||
body: generateBody()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||
|
||||
import 'package:adguard_home_manager/screens/settings/theme_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/server_info.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/section_label.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/appbar.dart';
|
||||
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
||||
|
@ -83,6 +84,19 @@ class Settings extends StatelessWidget {
|
|||
appBar: const SettingsAppBar(),
|
||||
body: ListView(
|
||||
children: [
|
||||
SectionLabel(label: AppLocalizations.of(context)!.serverSettings),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.info_rounded,
|
||||
label: AppLocalizations.of(context)!.serverInformation,
|
||||
description: AppLocalizations.of(context)!.serverInformationDescription,
|
||||
onTap: () => {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ServerInformation()
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
SectionLabel(label: AppLocalizations.of(context)!.appSettings),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.light_mode_rounded,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue