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

Ignore the first day of the week #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 lib/habits/calendar_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CalendarHeader extends StatelessWidget {
BuildContext ctx,
int index,
) {
int start = settingsManager.getWeekStartEnum.index;
int start = settingsManager.getWeekStartEnum?.index ?? (DateTime.now().weekday % 7);
int day = (start + index) % StartingDayOfWeek.values.length;
TextStyle tex = const TextStyle(fontSize: 18, color: Colors.grey);
if (day == 5 || day == 6) // Sat or Sun
Expand Down
2 changes: 1 addition & 1 deletion lib/habits/habit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class HabitState extends State<Habit> {
onPageChanged: setSelectedDay,
onDaySelected: _onDaySelected,
startingDayOfWeek:
Provider.of<SettingsManager>(context).getWeekStartEnum,
Provider.of<SettingsManager>(context).getWeekStartEnum ?? StartingDayOfWeek.values[DateTime.now().weekday % 7],
calendarBuilders: CalendarBuilders(
defaultBuilder: (context, date, _) {
return OneDayButton(
Expand Down
4 changes: 2 additions & 2 deletions lib/model/settings_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:table_calendar/table_calendar.dart';

class SettingsData {
Themes theme = Themes.device;
StartingDayOfWeek weekStart = StartingDayOfWeek.monday;
StartingDayOfWeek? weekStart = StartingDayOfWeek.monday;
TimeOfDay dailyNotTime = const TimeOfDay(hour: 20, minute: 0);
bool showDailyNot = true;
bool soundEffects = true;
Expand Down Expand Up @@ -43,7 +43,7 @@ class SettingsData {

Map<String, dynamic> toJson() => {
'theme': theme.index,
'weekStart': weekStart.index,
'weekStart': weekStart?.index,
'notTime':
'${dailyNotTime.hour.toString().padLeft(2, '0')}:${dailyNotTime.minute.toString().padLeft(2, '0')}',
'showDailyNot': showDailyNot,
Expand Down
4 changes: 2 additions & 2 deletions lib/settings/settings_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SettingsManager extends ChangeNotifier {
return _settingsData.theme;
}

StartingDayOfWeek get getWeekStartEnum {
StartingDayOfWeek? get getWeekStartEnum {
return _settingsData.weekStart;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ class SettingsManager extends ChangeNotifier {
notifyListeners();
}

set setWeekStart(StartingDayOfWeek value) {
set setWeekStart(StartingDayOfWeek? value) {
_settingsData.weekStart = value;
saveData();
notifyListeners();
Expand Down
15 changes: 12 additions & 3 deletions lib/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
trailing: DropdownButton<dynamic>(
alignment: Alignment.center,
items: StartingDayOfWeek.values.map((dynamic value) {
items: [...StartingDayOfWeek.values.map((dynamic value) {
return DropdownMenuItem<dynamic>(
alignment: Alignment.center,
value: value,
Expand All @@ -173,11 +173,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
);
}).toList(),
const DropdownMenuItem<dynamic>(
alignment: Alignment.center,
value: "None",
child: Text(
"None",
textAlign: TextAlign.center,
)
)
],
value: Provider.of<SettingsManager>(context)
.getWeekStartEnum,
.getWeekStartEnum ?? "None",
onChanged: (value) {
Provider.of<SettingsManager>(context, listen: false)
.setWeekStart = value;
.setWeekStart = value is String ? null : value;
},
),
),
Expand Down