Initial commit
This commit is contained in:
41
lib/features/main/presentation/bloc/main_bloc.dart
Normal file
41
lib/features/main/presentation/bloc/main_bloc.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
part 'main_event.dart';
|
||||
|
||||
part 'main_state.dart';
|
||||
|
||||
class MainBloc extends Bloc<MainEvent, MainState> {
|
||||
MainBloc() : super(const MainState(tab: MainTab.home)) {
|
||||
on<ChangeTabEvent>(_changeTab);
|
||||
}
|
||||
|
||||
void _changeTab(ChangeTabEvent event, Emitter<MainState> emit) {
|
||||
// if (state.tab != event.tab) {
|
||||
// changeTap(event.tab);
|
||||
// }
|
||||
emit(state.copyWith(tab: event.tab));
|
||||
}
|
||||
|
||||
// void changeTap(MainTab tab) {
|
||||
// switch (tab) {
|
||||
// case MainTab.home:
|
||||
// Navigator.of(
|
||||
// shellRootNavigatorKey.currentContext!,
|
||||
// ).pushNamedAndRemoveUntil(Routes.home, (route) => false);
|
||||
// break;
|
||||
// case MainTab.calculation:
|
||||
// Navigator.of(
|
||||
// shellRootNavigatorKey.currentContext!,
|
||||
// ).pushNamedAndRemoveUntil(Routes.calculation, (route) => false);
|
||||
// break;
|
||||
// case MainTab.profile:
|
||||
// Navigator.of(
|
||||
// shellRootNavigatorKey.currentContext!,
|
||||
// ).pushNamedAndRemoveUntil(Routes.profile, (route) => false);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
enum MainTab { home, calculation, profile }
|
||||
14
lib/features/main/presentation/bloc/main_event.dart
Normal file
14
lib/features/main/presentation/bloc/main_event.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
part of 'main_bloc.dart';
|
||||
|
||||
sealed class MainEvent extends Equatable {
|
||||
const MainEvent();
|
||||
}
|
||||
|
||||
final class ChangeTabEvent extends MainEvent {
|
||||
final MainTab tab;
|
||||
|
||||
const ChangeTabEvent({required this.tab});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [tab];
|
||||
}
|
||||
18
lib/features/main/presentation/bloc/main_state.dart
Normal file
18
lib/features/main/presentation/bloc/main_state.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
part of 'main_bloc.dart';
|
||||
|
||||
class MainState extends Equatable {
|
||||
final MainTab tab;
|
||||
|
||||
const MainState({
|
||||
required this.tab,
|
||||
});
|
||||
|
||||
MainState copyWith({
|
||||
MainTab? tab,
|
||||
}) {
|
||||
return MainState(tab: tab ?? this.tab);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [tab];
|
||||
}
|
||||
Reference in New Issue
Block a user