Revolution #1
2 changed files with 28 additions and 7 deletions
|
|
@ -8,9 +8,8 @@ class ApiController extends GetxController {
|
|||
|
||||
final apiStorageBox = GetStorage();
|
||||
|
||||
final _endPoint = "http://127.0.0.1:8000".obs;
|
||||
String get endPoint => _endPoint.value;
|
||||
set endPoint(String value) => _endPoint.value = value;
|
||||
String get endPoint => apiStorageBox.read<String>("endPoint") ?? "";
|
||||
set endPoint(String value) => apiStorageBox.write("endPoint", value);
|
||||
|
||||
String get token => apiStorageBox.read<String>("accessToken") ?? "";
|
||||
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';
|
||||
|
||||
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;
|
||||
String get username => _username.value;
|
||||
set username(String value) => _username.value = value;
|
||||
|
|
@ -19,12 +23,14 @@ class LoginPageController extends GetxController {
|
|||
bool get submitted => _submitted.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 {
|
||||
submitted = true;
|
||||
if (isFormValid) {
|
||||
try {
|
||||
ApiController.to.endPoint = endpoint;
|
||||
final resp = await ApiController.to.apiClient.getAccessToken(
|
||||
authModel: AuthModel(
|
||||
username: username,
|
||||
|
|
@ -100,6 +106,21 @@ class LoginPage extends GetView<LoginPageController> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
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(
|
||||
enabled: !controller.submitted,
|
||||
decoration: const InputDecoration(
|
||||
|
|
@ -131,7 +152,8 @@ class LoginPage extends GetView<LoginPageController> {
|
|||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: controller.submitted
|
||||
onPressed:
|
||||
!controller.isFormValid || controller.submitted
|
||||
? null
|
||||
: () => controller.submitForm(),
|
||||
child: const Text('Login'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue