aman-kassa-flutter/lib/views/home/home_view_model.dart

89 lines
2.9 KiB
Dart

import 'package:aman_kassa_flutter/core/base/base_view_model.dart';
import 'package:aman_kassa_flutter/core/entity/Category.dart';
import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/models/Choice.dart';
import 'package:aman_kassa_flutter/core/models/user.dart';
import 'package:aman_kassa_flutter/core/route_names.dart';
import 'package:aman_kassa_flutter/core/services/DataService.dart';
import 'package:aman_kassa_flutter/core/services/authentication_service.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
import 'package:flutter/material.dart';
class HomeViewModel extends BaseViewModel {
NavigatorService _navigationService;
AuthenticationService _authenticationService;
DataService _dataService;
final DialogService _dialogService = locator<DialogService>();
HomeViewModel({
@required AuthenticationService authenticationService,
@required NavigatorService navigationService,
@required DataService dataService,
}) : _authenticationService = authenticationService,
_dataService = dataService,
_navigationService = navigationService;
User _currentUser;
User get currentUser => _currentUser;
int _tabIndex = 0;
int get tabIndex => this._tabIndex;
set tabIndex(int index) {
this._tabIndex = index;
notifyListeners();
}
void onSelected(Choice choice) async {
log.i(choice.command);
if(choice.command == 'exit') {
bool result = await _authenticationService.logout(_currentUser.token);
if (result) {
_navigationService.replace(LoginViewRoute);
}
} else if (choice.command == 'update') {
log.i(_authenticationService.currentUser.token);
bool result = await _dataService.getDataFromServer(_authenticationService.currentUser.token);
log.i(result);
}
}
PageController get pageController => this._pageController;
PageController _pageController;
set pageController(PageController pageController) {
this._pageController = pageController;
}
List<Object> _bottomSheetElements = [];
List<Object> get bottomSheetElements => this._bottomSheetElements;
int _parentId;
void selectBottomElement(int parentId) async {
// log.i('parentId=$parentId');
// _parentId = parentId;
// _bottomSheetElements.clear();
// List<Category> categories = await _dataService.getCategoriesByParentId(parentId: parentId);
// List<Category> goods = await _dataService.getGoodsByCategoryId(categoryId: parentId);
// _bottomSheetElements.addAll(categories);
// _bottomSheetElements.addAll(goods);
// notifyListeners();
}
String _text;
get text => this._text;
set text(String text) => this._text = text;
void initialize() {
_currentUser = _authenticationService.currentUser;
}
@override
void dispose() {
super.dispose();
_pageController.dispose();
}
}