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

Use DateFormat to get the weekday labels #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
60 changes: 52 additions & 8 deletions lib/default_weekday_labels_row.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';

class CalendarroWeekdayLabelsView extends StatelessWidget {
final DateTime monday = DateTime(2020, 01, 06);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I like the idea :) but I don't like hardcoding specific dates. Is there no other way to do it ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that it's not ideal but unfortunately I don't know another way to make it works

final DateTime tuesday = DateTime(2020, 01, 07);
final DateTime wednesday = DateTime(2020, 01, 08);
final DateTime thursday = DateTime(2020, 01, 09);
final DateTime friday = DateTime(2020, 01, 10);
final DateTime saturday = DateTime(2020, 01, 11);
final DateTime sunday = DateTime(2020, 01, 12);

@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Expanded(child: Text("Mon", textAlign: TextAlign.center)),
Expanded(child: Text("Tue", textAlign: TextAlign.center)),
Expanded(child: Text("Wed", textAlign: TextAlign.center)),
Expanded(child: Text("Thu", textAlign: TextAlign.center)),
Expanded(child: Text("Fri", textAlign: TextAlign.center)),
Expanded(child: Text("Sat", textAlign: TextAlign.center)),
Expanded(child: Text("Sun", textAlign: TextAlign.center)),
Expanded(
child: Text(
DateFormat('E').format(monday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(tuesday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(wednesday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(thursday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(friday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(saturday),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
DateFormat('E').format(sunday),
textAlign: TextAlign.center,
),
),
],
);
}
}
}