Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#73] 버전 정보 가져오기 #75

Merged
merged 7 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
JAVA_VERSION: "21.x"
FLUTTER_VERSION: "3.19.3"
FLUTTER_VERSION: "3.24.3"

jobs:
analyze:
Expand Down
8 changes: 4 additions & 4 deletions lib/features/contest/screen/contest_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ class _ContestViewState extends State<ContestView> {
backgroundColor: state
.isOnNotificationUpcomingContests[
index]
? MaterialStateProperty.all(
? WidgetStateProperty.all(
MySolvedColor
.secondaryButtonBackground)
: MaterialStateProperty.all(
: WidgetStateProperty.all(
MySolvedColor.main),
),
icon: Icon(
Expand All @@ -197,10 +197,10 @@ class _ContestViewState extends State<ContestView> {
backgroundColor: state
.isOnCalendarUpcomingContests[
index]
? MaterialStateProperty.all(
? WidgetStateProperty.all(
MySolvedColor
.secondaryButtonBackground)
: MaterialStateProperty.all(
: WidgetStateProperty.all(
MySolvedColor.main),
),
icon: Icon(
Expand Down
23 changes: 18 additions & 5 deletions lib/features/root/bloc/root_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
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';

class RootBloc extends Bloc<RootEvent, RootState> {
final String handle;
RootBloc() : super(RootInitial()) {
on<VersionInfoInit>(_onInitVersion);
on<NavigationBarItemTapped>(_onItemTapped);
}

Future<void> _onInitVersion(
VersionInfoInit event,
Emitter<RootState> emit,
) async {
final packageInfo = await PackageInfo.fromPlatform();
emit(RootSuccess(tabIndex: state.tabIndex, version: packageInfo.version));
}

RootBloc({required this.handle}) : super(RootState(handle: handle)) {
on<NavigationBarItemTapped>(
(event, emit) => emit(state.copyWith(tabIndex: event.tabIndex)),
);
void _onItemTapped(
NavigationBarItemTapped event,
Emitter<RootState> emit,
) {
emit(state.copyWith(tabIndex: event.tabIndex));
}
}
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];
}
42 changes: 32 additions & 10 deletions lib/features/root/bloc/root_state.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
part of 'root_bloc.dart';

class RootState extends Equatable {
final String handle;
abstract class RootState extends Equatable {
final int tabIndex;

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

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

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

class RootInitial extends RootState {
const RootInitial({super.tabIndex = 0});

@override
RootInitial copyWith({int? tabIndex}) {
return RootInitial(
tabIndex: tabIndex ?? this.tabIndex,
);
}
}

class RootSuccess extends RootState {
const RootSuccess({
required super.tabIndex,
required this.version,
});

final String version;

@override
RootSuccess copyWith({int? tabIndex, String? version}) {
return RootSuccess(
tabIndex: tabIndex ?? this.tabIndex,
version: version ?? this.version,
);
}

@override
List<Object?> get props => [handle, tabIndex];
List<Object?> get props => [...super.props, version];
}
89 changes: 68 additions & 21 deletions lib/features/root/screen/root_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:contest_repository/contest_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:my_solved/app/bloc/app_bloc.dart';
import 'package:my_solved/components/atoms/button/my_solved_text_button.dart';
import 'package:my_solved/components/styles/color.dart';
import 'package:my_solved/components/styles/font.dart';
import 'package:my_solved/features/contest/bloc/contest_bloc.dart';
Expand All @@ -21,17 +20,15 @@ import 'package:user_repository/user_repository.dart';
class RootScreen extends StatelessWidget {
final String handle;

const RootScreen({required this.handle, super.key});
const RootScreen({super.key, required this.handle});

@override
Widget build(BuildContext context) {
final rootBloc = RootBloc();
rootBloc.add(VersionInfoInit());
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => RootBloc(
handle: handle,
),
),
BlocProvider.value(value: rootBloc),
BlocProvider(
create: (context) => HomeBloc(
userRepository: UserRepository(),
Expand All @@ -53,13 +50,15 @@ class RootScreen extends StatelessWidget {
),
),
],
child: RootView(),
child: RootView(handle: handle),
);
}
}

class RootView extends StatefulWidget {
const RootView({super.key});
const RootView({super.key, required this.handle});

final String handle;

@override
State<RootView> createState() => _RootViewState();
Expand Down Expand Up @@ -97,7 +96,10 @@ class _RootViewState extends State<RootView> {
return Scaffold(
key: _scaffoldKey,
backgroundColor: MySolvedColor.background,
endDrawer: HomeDrawer(homeBloc: context.read<HomeBloc>()),
endDrawer: HomeDrawer(
handle: widget.handle,
homeBloc: context.read<HomeBloc>(),
),
body: bottomNaviScreen.elementAt(state.tabIndex),
bottomNavigationBar: BottomNavigationBar(
items: bottomNavItems,
Expand All @@ -120,9 +122,14 @@ class _RootViewState extends State<RootView> {
}

class HomeDrawer extends StatelessWidget {
final String handle;
final HomeBloc homeBloc;

const HomeDrawer({super.key, required this.homeBloc});
const HomeDrawer({
super.key,
required this.handle,
required this.homeBloc,
});

@override
Widget build(BuildContext context) {
Expand All @@ -146,7 +153,7 @@ class HomeDrawer extends StatelessWidget {
Padding(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: Text(
context.read<RootBloc>().handle,
handle,
style: MySolvedTextStyle.title3,
),
),
Expand All @@ -156,20 +163,56 @@ class HomeDrawer extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MySolvedTextButton(
TextButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SettingScreen(homeBloc: homeBloc),
),
),
text: "설정",
style: ButtonStyle(
elevation: WidgetStateProperty.all(0),
overlayColor: WidgetStateProperty.all(Colors.transparent),
minimumSize: WidgetStateProperty.all(Size.zero),
padding: WidgetStateProperty.all(EdgeInsets.zero),
splashFactory: NoSplash.splashFactory,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"설정",
style: MySolvedTextStyle.body2.copyWith(
color: MySolvedColor.font,
),
),
],
),
),
SizedBox(height: 16),
MySolvedTextButton(
TextButton(
onPressed: () => context.read<AppBloc>().add(Logout()),
text: "로그아웃",
style: ButtonStyle(
elevation: WidgetStateProperty.all(0),
overlayColor: WidgetStateProperty.all(Colors.transparent),
minimumSize: WidgetStateProperty.all(Size.zero),
padding: WidgetStateProperty.all(EdgeInsets.zero),
splashFactory: NoSplash.splashFactory,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"로그아웃",
style: MySolvedTextStyle.body2.copyWith(
color: MySolvedColor.font,
),
),
],
),
),
],
),
Expand All @@ -181,11 +224,15 @@ class HomeDrawer extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("버전 정보", style: MySolvedTextStyle.body2),
Text(
"1.0.0",
style: MySolvedTextStyle.body2.copyWith(
color: MySolvedColor.secondaryFont,
),
BlocBuilder<RootBloc, RootState>(
builder: (context, state) {
return Text(
(state is RootSuccess) ? state.version : "",
style: MySolvedTextStyle.body2.copyWith(
color: MySolvedColor.secondaryFont,
),
);
},
),
],
),
Expand Down
8 changes: 4 additions & 4 deletions lib/features/search_filter/screen/search_filter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class _SearchFilterViewState extends State<SearchFilterView> {
inactiveThumbColor: MySolvedColor.background,
inactiveTrackColor:
MySolvedColor.disabledButtonBackground,
trackOutlineColor: MaterialStateProperty.resolveWith(
trackOutlineColor: WidgetStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(WidgetState.selected)) {
return null;
}
return MySolvedColor.disabledButtonBackground;
Expand Down Expand Up @@ -174,9 +174,9 @@ class _SearchFilterViewState extends State<SearchFilterView> {
inactiveThumbColor: MySolvedColor.background,
inactiveTrackColor:
MySolvedColor.disabledButtonBackground,
trackOutlineColor: MaterialStateProperty.resolveWith(
trackOutlineColor: WidgetStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(WidgetState.selected)) {
return null;
}
return MySolvedColor.disabledButtonBackground;
Expand Down
4 changes: 2 additions & 2 deletions lib/features/setting/screen/setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class _SettingViewState extends State<SettingView> {
inactiveThumbColor: MySolvedColor.background,
inactiveTrackColor:
MySolvedColor.disabledButtonBackground,
trackOutlineColor: MaterialStateProperty.resolveWith(
trackOutlineColor: WidgetStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(WidgetState.selected)) {
return null;
}
return MySolvedColor.disabledButtonBackground;
Expand Down
7 changes: 4 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
flutter:
sdk: flutter

add_2_calendar: ^3.0.1
cupertino_icons: ^1.0.5
equatable: ^2.0.5
extended_image: ^8.1.0
Expand All @@ -20,20 +21,20 @@ dependencies:
flutter_local_notifications: ^17.2.3
flutter_native_timezone: ^2.0.0
flutter_radar_chart: ^0.2.1
pie_chart: ^5.4.0
flutter_staggered_grid_view: ^0.7.0
flutter_svg: ^2.0.7
flutter_widget_from_html_core: ^0.14.11
html: ^0.15.2
http: ^1.1.0
intl: ^0.18.0
meta: ^1.9.1
package_info_plus: ^8.0.2
permission_handler: ^11.3.1
pie_chart: ^5.4.0
provider: ^6.0.5
shared_preferences: ^2.0.18
timezone: ^0.9.1
url_launcher: ^6.1.10
permission_handler: ^11.3.1
add_2_calendar: ^3.0.1

boj_api:
path: packages/apis/boj_api
Expand Down