Skip to content

Commit

Permalink
feat: 버전 정보 가져오기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jayden000106 committed Oct 14, 2024
1 parent b02a9e8 commit ff70d67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions lib/features/root/bloc/root_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:meta/meta.dart';
import 'package:package_info_plus/package_info_plus.dart';

part 'root_event.dart';
part 'root_state.dart';
Expand All @@ -9,6 +10,12 @@ class RootBloc extends Bloc<RootEvent, RootState> {
final String handle;

RootBloc({required this.handle}) : super(RootState(handle: handle)) {
on<VersionInfoInit>(
(event, emit) async {
final packageInfo = await PackageInfo.fromPlatform();
emit(state.copyWith(version: packageInfo.version));
},
);
on<NavigationBarItemTapped>(
(event, emit) => emit(state.copyWith(tabIndex: event.tabIndex)),
);
Expand Down
7 changes: 3 additions & 4 deletions lib/features/root/bloc/root_event.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
part of 'root_bloc.dart';

@immutable
abstract class RootEvent extends Equatable {}
abstract class RootEvent {}

class VersionInfoInit extends RootEvent {}

class NavigationBarItemTapped extends RootEvent {
final int tabIndex;

NavigationBarItemTapped({required this.tabIndex});

@override
List<Object?> get props => [tabIndex];
}
11 changes: 9 additions & 2 deletions lib/features/root/bloc/root_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ part of 'root_bloc.dart';
class RootState extends Equatable {
final String handle;
final int tabIndex;
final String version;

const RootState({required this.handle, this.tabIndex = 0});
const RootState({
required this.handle,
this.tabIndex = 0,
this.version = "",
});

RootState copyWith({
String? handle,
int? tabIndex,
String? version,
}) {
return RootState(
handle: handle ?? this.handle,
tabIndex: tabIndex ?? this.tabIndex,
version: version ?? this.version,
);
}

@override
List<Object?> get props => [handle, tabIndex];
List<Object?> get props => [handle, tabIndex, version];
}

0 comments on commit ff70d67

Please sign in to comment.