-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the user the ability to choose the time format
- Loading branch information
1 parent
c88e78f
commit 02addf7
Showing
31 changed files
with
844 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:chabo/const.dart'; | ||
import 'package:chabo/models/enums/time_format.dart'; | ||
import 'package:chabo/service/storage_service.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class TimeFormatCubit extends Cubit<TimeFormatState> { | ||
final StorageService storageService; | ||
|
||
TimeFormatCubit(this.storageService, super.initialState); | ||
|
||
void setTimeFormat() { | ||
final newDateFormat = state.timeFormat == TimeFormat.twentyFourHours | ||
? TimeFormat.twelveHours | ||
: TimeFormat.twentyFourHours; | ||
storageService.saveTimeFormat(Const.timeFormatKey, newDateFormat); | ||
emit( | ||
state.copyWith( | ||
timeFormat: newDateFormat, | ||
), | ||
); | ||
} | ||
|
||
void init() { | ||
final timeFormat = storageService.readTimeFormat(Const.timeFormatKey) ?? | ||
Const.timeFormatDefaultValue; | ||
emit( | ||
state.copyWith( | ||
timeFormat: timeFormat, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class TimeFormatState extends Equatable { | ||
final TimeFormat timeFormat; | ||
|
||
const TimeFormatState({ | ||
required this.timeFormat, | ||
}); | ||
|
||
TimeFormatState copyWith({TimeFormat? timeFormat}) { | ||
return TimeFormatState( | ||
timeFormat: timeFormat ?? this.timeFormat, | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [timeFormat]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.