Improvements
This commit is contained in:
@@ -1,57 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:linkdy/helpers/wrapped_class.dart';
|
||||
|
||||
class ConnectModel {
|
||||
final bool isConnecting;
|
||||
final int method;
|
||||
bool isConnecting;
|
||||
int method;
|
||||
final TextEditingController ipDomainController;
|
||||
final String? ipDomainError;
|
||||
String? ipDomainError;
|
||||
final TextEditingController portController;
|
||||
final String? portError;
|
||||
String? portError;
|
||||
final TextEditingController pathController;
|
||||
final String? pathError;
|
||||
String? pathError;
|
||||
final TextEditingController tokenController;
|
||||
final String? tokenError;
|
||||
final bool validValues;
|
||||
String? tokenError;
|
||||
bool validValues;
|
||||
|
||||
ConnectModel({
|
||||
required this.isConnecting,
|
||||
required this.method,
|
||||
this.isConnecting = false,
|
||||
this.method = 0,
|
||||
required this.ipDomainController,
|
||||
required this.ipDomainError,
|
||||
this.ipDomainError,
|
||||
required this.portController,
|
||||
required this.portError,
|
||||
this.portError,
|
||||
required this.pathController,
|
||||
required this.pathError,
|
||||
this.pathError,
|
||||
required this.tokenController,
|
||||
required this.tokenError,
|
||||
required this.validValues,
|
||||
this.tokenError,
|
||||
this.validValues = true,
|
||||
});
|
||||
|
||||
ConnectModel copyWidth({
|
||||
bool? isConnecting,
|
||||
int? method,
|
||||
TextEditingController? ipDomainController,
|
||||
Wrapped<String?>? ipDomainError,
|
||||
TextEditingController? portController,
|
||||
Wrapped<String?>? portError,
|
||||
TextEditingController? pathController,
|
||||
Wrapped<String?>? pathError,
|
||||
TextEditingController? tokenController,
|
||||
Wrapped<String?>? tokenError,
|
||||
bool? validValues,
|
||||
}) =>
|
||||
ConnectModel(
|
||||
isConnecting: isConnecting ?? this.isConnecting,
|
||||
method: method ?? this.method,
|
||||
ipDomainController: ipDomainController ?? this.ipDomainController,
|
||||
ipDomainError: ipDomainError != null ? ipDomainError.value : this.ipDomainError,
|
||||
portController: portController ?? this.portController,
|
||||
portError: portError != null ? portError.value : this.portError,
|
||||
pathController: pathController ?? this.pathController,
|
||||
pathError: pathError != null ? pathError.value : this.pathError,
|
||||
tokenController: tokenController ?? this.tokenController,
|
||||
tokenError: tokenError != null ? tokenError.value : this.tokenError,
|
||||
validValues: validValues ?? this.validValues,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ class OnboardingModel {
|
||||
required this.pageController,
|
||||
this.confirmServerRunning = false,
|
||||
});
|
||||
|
||||
OnboardingModel toggleConfirmServerRunning(bool newValue) => OnboardingModel(
|
||||
pageController: pageController,
|
||||
confirmServerRunning: newValue,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:linkdy/models/server_instance.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
import 'package:linkdy/services/api_client.dart';
|
||||
import 'package:linkdy/constants/regexp.dart';
|
||||
import 'package:linkdy/helpers/wrapped_class.dart';
|
||||
|
||||
part 'connect.provider.g.dart';
|
||||
|
||||
@@ -39,36 +38,40 @@ class Connect extends _$Connect {
|
||||
}
|
||||
|
||||
void setConnectionMethod(int method) {
|
||||
state = state.copyWidth(method: method);
|
||||
state.method = method;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void validateIpDomain(String value) {
|
||||
if (Regexps.ipAddress.hasMatch(value) || Regexps.domain.hasMatch(value)) {
|
||||
state = state.copyWidth(ipDomainError: const Wrapped.value(null));
|
||||
state.ipDomainError = null;
|
||||
} else {
|
||||
state = state.copyWidth(ipDomainError: const Wrapped.value("Error"));
|
||||
state.ipDomainError = "Error";
|
||||
}
|
||||
state = state.copyWidth(validValues: validValues());
|
||||
state.validValues = validValues();
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void validatePort(value) {
|
||||
if (value != null && value != '') {
|
||||
if (int.tryParse(value) != null && int.parse(value) <= 65535) {
|
||||
state = state.copyWidth(portError: const Wrapped.value(null));
|
||||
state.portError = null;
|
||||
} else {
|
||||
state = state.copyWidth(portError: const Wrapped.value("Invalid port"));
|
||||
state.portError = "Invalid port";
|
||||
}
|
||||
}
|
||||
state = state.copyWidth(validValues: validValues());
|
||||
state.validValues = validValues();
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void validateToken(String value) {
|
||||
if (value != "") {
|
||||
state = state.copyWidth(tokenError: const Wrapped.value(null));
|
||||
state.tokenError = null;
|
||||
} else {
|
||||
state = state.copyWidth(tokenError: const Wrapped.value("Error"));
|
||||
state.tokenError = "Error";
|
||||
}
|
||||
state = state.copyWidth(validValues: validValues());
|
||||
state.validValues = validValues();
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
bool validValues() {
|
||||
|
||||
@@ -21,7 +21,7 @@ final connectToServerProvider = AutoDisposeFutureProvider<bool>.internal(
|
||||
);
|
||||
|
||||
typedef ConnectToServerRef = AutoDisposeFutureProviderRef<bool>;
|
||||
String _$connectHash() => r'2c2e4fff717252259381056b4767b9a4511b5009';
|
||||
String _$connectHash() => r'348a51c7ab10af474e09ec3ffdcedffa46156695';
|
||||
|
||||
/// See also [Connect].
|
||||
@ProviderFor(Connect)
|
||||
|
||||
Reference in New Issue
Block a user