import 'package:aman_kassa_flutter/core/base/base_view_model.dart'; import 'package:aman_kassa_flutter/core/route_names.dart'; import 'package:aman_kassa_flutter/core/services/authentication_service.dart'; import 'package:aman_kassa_flutter/core/services/navigator_service.dart'; import 'package:flutter/material.dart'; import 'package:aman_kassa_flutter/core/models/authResponse.dart'; class LoginViewModel extends BaseViewModel { //service NavigatorService _navigationService; AuthenticationService _authenticationService; //private var String _messageEmail; String _messagePassword; //public getter setter get messageEmail => this._messageEmail; set messageEmail(String message) { this._messageEmail = message; notifyListeners(); } get messagePassword => this._messagePassword; set messagePassword(String message) { this._messagePassword = message; notifyListeners(); } LoginViewModel({ @required AuthenticationService authenticationService, @required NavigatorService navigationService, }) : _authenticationService = authenticationService , _navigationService = navigationService; Future login({String email, String password}) async { String result; busy = true; try { AuthBody response = await _authenticationService.loginWithEmail(email: email, password: password); if(response!=null) { if(response.user != null){ _navigationService.replace(HomeViewRoute); } else { // show error on validate if(response.email?.isEmpty == false){ messageEmail = response.email.join(","); } else { messageEmail = null; } if(response.password?.isEmpty == false){ messagePassword = response.password.join(","); } else { messagePassword = null; } //return meesage on snackbar for user screen if(response.message!=null) { result = response.message; } } } } finally { busy = false ; } return result; } // Add ViewModel specific code here }