forked from eatvio/eatvio_app
Added height screen for registration & set adequate options and initial parameters for height/weight
This commit is contained in:
40
lib/presentation/height_screen/bloc/height_bloc.dart
Normal file
40
lib/presentation/height_screen/bloc/height_bloc.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '/core/app_export.dart';
|
||||
import 'package:eatvio_app/presentation/height_screen/models/height_model.dart';
|
||||
part 'height_event.dart';
|
||||
part 'height_state.dart';
|
||||
|
||||
/// A bloc that manages the state of a Height according to the event that is dispatched to it.
|
||||
class HeightBloc extends Bloc<HeightEvent, HeightState> {
|
||||
HeightBloc(HeightState initialState) : super(initialState) {
|
||||
on<HeightInitialEvent>(_onInitialize);
|
||||
on<ChangeDropDownEvent>(_changeDropDown);
|
||||
}
|
||||
|
||||
_onInitialize(
|
||||
HeightInitialEvent event,
|
||||
Emitter<HeightState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(
|
||||
heightModelObj: state.heightModelObj
|
||||
?.copyWith(dropdownItemList: fillDropdownItemList())));
|
||||
}
|
||||
|
||||
_changeDropDown(
|
||||
ChangeDropDownEvent event,
|
||||
Emitter<HeightState> emit,
|
||||
) {
|
||||
emit(state.copyWith(selectedDropDownValue: event.value));
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> fillDropdownItemList() {
|
||||
List<SelectionPopupModel> selectionPopupModels = [];
|
||||
|
||||
for (int i = 140; i <= 220; i++) {
|
||||
selectionPopupModels
|
||||
.add(SelectionPopupModel(id: i - 34, title: i.toString()));
|
||||
}
|
||||
return selectionPopupModels;
|
||||
}
|
||||
}
|
||||
28
lib/presentation/height_screen/bloc/height_event.dart
Normal file
28
lib/presentation/height_screen/bloc/height_event.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
part of 'height_bloc.dart';
|
||||
|
||||
/// Abstract class for all events that can be dispatched from the
|
||||
///Height widget.
|
||||
///
|
||||
/// Events must be immutable and implement the [Equatable] interface.
|
||||
@immutable
|
||||
abstract class HeightEvent extends Equatable {}
|
||||
|
||||
/// Event that is dispatched when the Height widget is first created.
|
||||
class HeightInitialEvent extends HeightEvent {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
///event for dropdown selection
|
||||
class ChangeDropDownEvent extends HeightEvent {
|
||||
ChangeDropDownEvent({required this.value});
|
||||
|
||||
SelectionPopupModel value;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
value,
|
||||
];
|
||||
}
|
||||
31
lib/presentation/height_screen/bloc/height_state.dart
Normal file
31
lib/presentation/height_screen/bloc/height_state.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
part of 'height_bloc.dart';
|
||||
|
||||
/// Represents the state of Height in the application.
|
||||
class HeightState extends Equatable {
|
||||
HeightState({
|
||||
this.selectedDropDownValue,
|
||||
this.heightModelObj,
|
||||
});
|
||||
|
||||
SelectionPopupModel? selectedDropDownValue;
|
||||
|
||||
HeightModel? heightModelObj;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
selectedDropDownValue,
|
||||
heightModelObj,
|
||||
];
|
||||
HeightState copyWith({
|
||||
SelectionPopupModel? selectedDropDownValue,
|
||||
HeightModel? heightModelObj,
|
||||
}) {
|
||||
return HeightState(
|
||||
selectedDropDownValue:
|
||||
selectedDropDownValue ?? this.selectedDropDownValue,
|
||||
heightModelObj: heightModelObj ?? this.heightModelObj,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user