mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-06-08 07:37:44 +00:00
Improvements and fixes
This commit is contained in:
parent
2389e34571
commit
36bd7acfed
2 changed files with 59 additions and 77 deletions
|
@ -68,7 +68,7 @@ String? validateAddress({
|
||||||
}) {
|
}) {
|
||||||
if (value != null && value != '') {
|
if (value != null && value != '') {
|
||||||
RegExp ipAddress = RegExp(r'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$');
|
RegExp ipAddress = RegExp(r'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$');
|
||||||
RegExp domain = RegExp(r'^(([a-z0-9|-]+\.)*[a-z0-9|-]+\.[a-z]+)|((\w|-)+)$');
|
RegExp domain = RegExp(r'^(([a-z0-9|-]+\.)*[a-z0-9|-]+\.[a-z]+)$');
|
||||||
if (ipAddress.hasMatch(value) == true || domain.hasMatch(value) == true) {
|
if (ipAddress.hasMatch(value) == true || domain.hasMatch(value) == true) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import 'package:uuid/uuid.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/widgets/add_server/form_text_field.dart';
|
import 'package:adguard_home_manager/widgets/add_server/form_text_field.dart';
|
||||||
|
import 'package:adguard_home_manager/widgets/section_label.dart';
|
||||||
|
import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
|
||||||
import 'package:adguard_home_manager/widgets/add_server/add_server_functions.dart';
|
import 'package:adguard_home_manager/widgets/add_server/add_server_functions.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||||
|
@ -67,23 +69,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
|
|
||||||
bool isConnecting = false;
|
bool isConnecting = false;
|
||||||
|
|
||||||
Widget sectionLabel(String label) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 24,
|
|
||||||
vertical: 24
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Theme.of(context).colorScheme.primary
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.server != null) {
|
if (widget.server != null) {
|
||||||
|
@ -166,12 +151,13 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
cancelConnecting();
|
cancelConnecting();
|
||||||
appConfigProvider.addLog(result['log']);
|
appConfigProvider.addLog(result['log']);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
return showSnacbkar(
|
showSnacbkar(
|
||||||
appConfigProvider: appConfigProvider,
|
appConfigProvider: appConfigProvider,
|
||||||
label: getErrorMessage(result['result']),
|
label: getErrorMessage(result['result']),
|
||||||
color: Colors.red
|
color: Colors.red
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverObj.user != null && serverObj.password != null) {
|
if (serverObj.user != null && serverObj.password != null) {
|
||||||
|
@ -181,7 +167,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
final serverCreated = await serversProvider.createServer(serverObj);
|
final serverCreated = await serversProvider.createServer(serverObj);
|
||||||
|
|
||||||
// If something goes wrong when saving the connection on the db
|
// If something goes wrong when saving the connection on the db
|
||||||
if (serverCreated == null) {
|
if (serverCreated != null) {
|
||||||
if (mounted) setState(() => isConnecting = false);
|
if (mounted) setState(() => isConnecting = false);
|
||||||
appConfigProvider.addLog(
|
appConfigProvider.addLog(
|
||||||
AppLog(
|
AppLog(
|
||||||
|
@ -197,6 +183,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
color: Colors.red
|
color: Colors.red
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
statusProvider.setServerStatusLoad(LoadStatus.loading);
|
statusProvider.setServerStatusLoad(LoadStatus.loading);
|
||||||
|
@ -208,6 +195,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
appConfigProvider.addLog(serverStatus['log']);
|
appConfigProvider.addLog(serverStatus['log']);
|
||||||
statusProvider.setServerStatusLoad(LoadStatus.error);
|
statusProvider.setServerStatusLoad(LoadStatus.error);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If everything is successful
|
// If everything is successful
|
||||||
|
@ -223,6 +211,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
else {
|
else {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void edit() async {
|
void edit() async {
|
||||||
|
@ -250,12 +239,13 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
cancelConnecting();
|
cancelConnecting();
|
||||||
appConfigProvider.addLog(result['log']);
|
appConfigProvider.addLog(result['log']);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
return showSnacbkar(
|
showSnacbkar(
|
||||||
appConfigProvider: appConfigProvider,
|
appConfigProvider: appConfigProvider,
|
||||||
label: getErrorMessage(result['result']),
|
label: getErrorMessage(result['result']),
|
||||||
color: Colors.red
|
color: Colors.red
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverObj.user != null && serverObj.password != null) {
|
if (serverObj.user != null && serverObj.password != null) {
|
||||||
|
@ -264,7 +254,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
final serverSaved = await serversProvider.editServer(serverObj);
|
final serverSaved = await serversProvider.editServer(serverObj);
|
||||||
|
|
||||||
// If something goes wrong when saving the connection on the db
|
// If something goes wrong when saving the connection on the db
|
||||||
if (serverSaved == null) {
|
if (serverSaved != null) {
|
||||||
if (mounted) setState(() => isConnecting = false);
|
if (mounted) setState(() => isConnecting = false);
|
||||||
appConfigProvider.addLog(
|
appConfigProvider.addLog(
|
||||||
AppLog(
|
AppLog(
|
||||||
|
@ -280,6 +270,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
color: Colors.red
|
color: Colors.red
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If everything is successful
|
// If everything is successful
|
||||||
|
@ -295,6 +286,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
else {
|
else {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget actions() {
|
Widget actions() {
|
||||||
|
@ -314,7 +306,11 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
: () => edit()
|
: () => edit()
|
||||||
: null,
|
: null,
|
||||||
icon: isConnecting
|
icon: isConnecting
|
||||||
? const CircularProgressIndicator()
|
? const SizedBox(
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator()
|
||||||
|
)
|
||||||
: Icon(
|
: Icon(
|
||||||
widget.server == null
|
widget.server == null
|
||||||
? Icons.login_rounded
|
? Icons.login_rounded
|
||||||
|
@ -350,7 +346,10 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
sectionLabel(AppLocalizations.of(context)!.general),
|
SectionLabel(
|
||||||
|
label: AppLocalizations.of(context)!.general,
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
),
|
||||||
FormTextField(
|
FormTextField(
|
||||||
label: AppLocalizations.of(context)!.name,
|
label: AppLocalizations.of(context)!.name,
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
|
@ -367,7 +366,10 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
},
|
},
|
||||||
isConnecting: isConnecting,
|
isConnecting: isConnecting,
|
||||||
),
|
),
|
||||||
sectionLabel(AppLocalizations.of(context)!.connection),
|
SectionLabel(
|
||||||
|
label: AppLocalizations.of(context)!.connection,
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
child: SegmentedButton<ConnectionType>(
|
child: SegmentedButton<ConnectionType>(
|
||||||
|
@ -425,7 +427,10 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
},
|
},
|
||||||
isConnecting: isConnecting,
|
isConnecting: isConnecting,
|
||||||
),
|
),
|
||||||
sectionLabel(AppLocalizations.of(context)!.authentication),
|
SectionLabel(
|
||||||
|
label: AppLocalizations.of(context)!.authentication,
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
),
|
||||||
FormTextField(
|
FormTextField(
|
||||||
label: AppLocalizations.of(context)!.username,
|
label: AppLocalizations.of(context)!.username,
|
||||||
controller: userController,
|
controller: userController,
|
||||||
|
@ -441,58 +446,32 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
isConnecting: isConnecting,
|
isConnecting: isConnecting,
|
||||||
),
|
),
|
||||||
sectionLabel(AppLocalizations.of(context)!.other),
|
SectionLabel(
|
||||||
Material(
|
label: AppLocalizations.of(context)!.other,
|
||||||
color: Colors.transparent,
|
padding: const EdgeInsets.only(
|
||||||
child: InkWell(
|
top: 32,
|
||||||
onTap: widget.server == null
|
left: 24,
|
||||||
? () => setState(() => defaultServer = !defaultServer)
|
bottom: 12
|
||||||
: null,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context)!.defaultServer,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Switch(
|
CustomSwitchListTile(
|
||||||
value: defaultServer,
|
value: defaultServer,
|
||||||
onChanged: widget.server == null
|
onChanged: (value) => setState(() => defaultServer = value),
|
||||||
? (value) => setState(() => defaultServer = value)
|
title: AppLocalizations.of(context)!.defaultServer,
|
||||||
: null,
|
disabled: widget.server != null || isConnecting,
|
||||||
)
|
padding: const EdgeInsets.symmetric(
|
||||||
],
|
horizontal: 24,
|
||||||
|
vertical: 4
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
CustomSwitchListTile(
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => setState(() => homeAssistant = !homeAssistant),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context)!.runningHomeAssistant,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Switch(
|
|
||||||
value: homeAssistant,
|
value: homeAssistant,
|
||||||
onChanged: (value) => setState(() => homeAssistant = value),
|
onChanged: (value) => setState(() => homeAssistant = value),
|
||||||
)
|
title: AppLocalizations.of(context)!.runningHomeAssistant,
|
||||||
],
|
disabled: widget.server != null || isConnecting,
|
||||||
),
|
padding: const EdgeInsets.symmetric(
|
||||||
),
|
horizontal: 24,
|
||||||
|
vertical: 4
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
@ -503,6 +482,9 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
return Dialog.fullscreen(
|
return Dialog.fullscreen(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
leading: CloseButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
title: widget.server != null
|
title: widget.server != null
|
||||||
? Text(AppLocalizations.of(context)!.createConnection)
|
? Text(AppLocalizations.of(context)!.createConnection)
|
||||||
: Text(AppLocalizations.of(context)!.editConnection),
|
: Text(AppLocalizations.of(context)!.editConnection),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue