Added endpoint field on login page
This commit is contained in:
parent
bce8e97368
commit
b755d60939
2 changed files with 28 additions and 7 deletions
|
|
@ -8,9 +8,8 @@ class ApiController extends GetxController {
|
||||||
|
|
||||||
final apiStorageBox = GetStorage();
|
final apiStorageBox = GetStorage();
|
||||||
|
|
||||||
final _endPoint = "http://127.0.0.1:8000".obs;
|
String get endPoint => apiStorageBox.read<String>("endPoint") ?? "";
|
||||||
String get endPoint => _endPoint.value;
|
set endPoint(String value) => apiStorageBox.write("endPoint", value);
|
||||||
set endPoint(String value) => _endPoint.value = value;
|
|
||||||
|
|
||||||
String get token => apiStorageBox.read<String>("accessToken") ?? "";
|
String get token => apiStorageBox.read<String>("accessToken") ?? "";
|
||||||
set token(String value) => apiStorageBox.write("accessToken", value);
|
set token(String value) => apiStorageBox.write("accessToken", value);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ import 'package:tuuli_api/tuuli_api.dart';
|
||||||
import 'package:tuuli_app/api_controller.dart';
|
import 'package:tuuli_app/api_controller.dart';
|
||||||
|
|
||||||
class LoginPageController extends GetxController {
|
class LoginPageController extends GetxController {
|
||||||
|
final _endpoint = ApiController.to.endPoint.obs;
|
||||||
|
String get endpoint => _endpoint.value;
|
||||||
|
set endpoint(String value) => _endpoint.value = value;
|
||||||
|
|
||||||
final _username = "".obs;
|
final _username = "".obs;
|
||||||
String get username => _username.value;
|
String get username => _username.value;
|
||||||
set username(String value) => _username.value = value;
|
set username(String value) => _username.value = value;
|
||||||
|
|
@ -19,12 +23,14 @@ class LoginPageController extends GetxController {
|
||||||
bool get submitted => _submitted.value;
|
bool get submitted => _submitted.value;
|
||||||
set submitted(bool value) => _submitted.value = value;
|
set submitted(bool value) => _submitted.value = value;
|
||||||
|
|
||||||
bool get isFormValid => username.isNotEmpty && password.isNotEmpty;
|
bool get isFormValid =>
|
||||||
|
endpoint.isNotEmpty && username.isNotEmpty && password.isNotEmpty;
|
||||||
|
|
||||||
Future<void> submitForm() async {
|
Future<void> submitForm() async {
|
||||||
submitted = true;
|
submitted = true;
|
||||||
if (isFormValid) {
|
if (isFormValid) {
|
||||||
try {
|
try {
|
||||||
|
ApiController.to.endPoint = endpoint;
|
||||||
final resp = await ApiController.to.apiClient.getAccessToken(
|
final resp = await ApiController.to.apiClient.getAccessToken(
|
||||||
authModel: AuthModel(
|
authModel: AuthModel(
|
||||||
username: username,
|
username: username,
|
||||||
|
|
@ -100,6 +106,21 @@ class LoginPage extends GetView<LoginPageController> {
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
enabled: !controller.submitted,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Endpoint',
|
||||||
|
hintText: 'Enter Tuuli Endpoint',
|
||||||
|
),
|
||||||
|
initialValue: ApiController.to.endPoint,
|
||||||
|
onChanged: (value) => controller.endpoint = value,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Please enter Tuuli Endpoint';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
enabled: !controller.submitted,
|
enabled: !controller.submitted,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
|
|
@ -131,7 +152,8 @@ class LoginPage extends GetView<LoginPageController> {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: controller.submitted
|
onPressed:
|
||||||
|
!controller.isFormValid || controller.submitted
|
||||||
? null
|
? null
|
||||||
: () => controller.submitForm(),
|
: () => controller.submitForm(),
|
||||||
child: const Text('Login'),
|
child: const Text('Login'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue