WT 1.1.11+3 Evaluation, null-safe fixes
This commit is contained in:
@@ -9,6 +9,8 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../../model/fitness_state.dart';
|
||||
|
||||
part 'customer_change_event.dart';
|
||||
part 'customer_change_state.dart';
|
||||
|
||||
@@ -19,14 +21,40 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
double weight = 60;
|
||||
double height = 170;
|
||||
CustomerChangeBloc({required this.customerRepository}) : super(CustomerChangeInitial()) {
|
||||
year = this.customerRepository.customer.birthYear;
|
||||
if (this.customerRepository.customer == null) {
|
||||
this.customerRepository.createNew();
|
||||
}
|
||||
year = this.customerRepository.customer!.birthYear;
|
||||
if (year == null || year == 0) {
|
||||
year = 1990;
|
||||
}
|
||||
weight = this.customerRepository.getWeight() == 0 ? 60 : this.customerRepository.getWeight();
|
||||
height = this.customerRepository.getHeight() == 0 ? 170 : this.customerRepository.getHeight();
|
||||
|
||||
print("fitnesslevel " + customerRepository.customer!.fitnessLevel.toString());
|
||||
if (customerRepository.customer!.fitnessLevel != null) {
|
||||
if (!FitnessItem().elements.contains(customerRepository.customer!.fitnessLevel)) {
|
||||
Sport.values.forEach((element) {
|
||||
print(" .. ${element.toStr()}");
|
||||
if (element.equalsStringTo(customerRepository.customer!.fitnessLevel!)) {
|
||||
selectedSport = element;
|
||||
selectedFitnessItem = FitnessState.professional;
|
||||
}
|
||||
});
|
||||
if (selectedSport == null) {
|
||||
selectedFitnessItem = customerRepository.customer!.fitnessLevel;
|
||||
}
|
||||
} else {
|
||||
selectedFitnessItem = customerRepository.customer!.fitnessLevel;
|
||||
}
|
||||
}
|
||||
|
||||
print("selected: $selectedFitnessItem sport: $selectedSport " + customerRepository.customer!.fitnessLevel.toString());
|
||||
}
|
||||
|
||||
Sport? selectedSport;
|
||||
String? selectedFitnessItem;
|
||||
|
||||
@override
|
||||
Stream<CustomerChangeState> mapEventToState(
|
||||
CustomerChangeEvent event,
|
||||
@@ -42,7 +70,8 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
visiblePassword = !visiblePassword;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerFitnessChange) {
|
||||
customerRepository.setFitnessLevel(event.fitness);
|
||||
//customerRepository.setFitnessLevel(event.fitness);
|
||||
selectedFitnessItem = event.fitness;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerBirthYearChange) {
|
||||
yield CustomerChangeLoading();
|
||||
@@ -77,9 +106,25 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
} else if (event is CustomerGenderChange) {
|
||||
customerRepository.setSex(event.gender == 0 ? "m" : "w");
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSportChange) {
|
||||
yield CustomerChangeLoading();
|
||||
selectedSport = event.sport;
|
||||
//customerRepository.setFitnessLevel(event.sport.toStr());
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSave) {
|
||||
yield CustomerSaving();
|
||||
if (validation()) {
|
||||
if (selectedFitnessItem != null) {
|
||||
if (selectedFitnessItem == FitnessState.professional) {
|
||||
if (selectedSport != null) {
|
||||
customerRepository.setFitnessLevel(selectedSport!.toStr());
|
||||
} else {
|
||||
customerRepository.setFitnessLevel(FitnessState.professional);
|
||||
}
|
||||
} else {
|
||||
customerRepository.setFitnessLevel(selectedFitnessItem!);
|
||||
}
|
||||
}
|
||||
await customerRepository.saveCustomer();
|
||||
Cache().initBadges();
|
||||
yield CustomerSaveSuccess();
|
||||
@@ -123,4 +168,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Sport? get getSelectedSport => this.selectedSport;
|
||||
set setSelectedSport(Sport? selectedSport) => this.selectedSport = selectedSport;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,14 @@ class CustomerPasswordChange extends CustomerChangeEvent {
|
||||
List<Object> get props => [password];
|
||||
}
|
||||
|
||||
class CustomerSportChange extends CustomerChangeEvent {
|
||||
final Sport sport;
|
||||
const CustomerSportChange({required this.sport});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sport];
|
||||
}
|
||||
|
||||
class CustomerChangePasswordObscure extends CustomerChangeEvent {
|
||||
const CustomerChangePasswordObscure();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user