Skip to content

Commit

Permalink
Merge pull request #16 from JonasWanke/issue/15-customizable-date-wee…
Browse files Browse the repository at this point in the history
…kday-format

Customizable date weekday format
  • Loading branch information
JonasWanke authored Jun 15, 2020
2 parents 11b9244 + 04731e7 commit edae72d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/src/header/date_indicator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:black_hole_flutter/black_hole_flutter.dart';
import 'package:flutter/material.dart';
import 'package:time_machine/time_machine.dart';
import 'package:time_machine/time_machine_text_patterns.dart';

import '../theme.dart';
import '../utils/utils.dart';
Expand All @@ -16,6 +17,8 @@ class DateIndicator extends StatelessWidget {
final timetableTheme = context.timetableTheme;

final states = statesFor(date);
final pattern = timetableTheme?.dateIndicatorPattern?.resolve(states) ??
LocalDatePattern.createWithCurrentCulture('%d');
final primaryColor = timetableTheme?.primaryColor ?? theme.primaryColor;
final decoration =
timetableTheme?.dateIndicatorDecoration?.resolve(states) ??
Expand All @@ -34,10 +37,7 @@ class DateIndicator extends StatelessWidget {
decoration: decoration,
child: Padding(
padding: EdgeInsets.all(8),
child: Text(
date.dayOfMonth.toString(),
style: textStyle,
),
child: Text(pattern.format(date), style: textStyle),
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/header/timetable_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:time_machine/time_machine.dart';

import '../controller.dart';
import '../event.dart';
import '../theme.dart';
import '../timetable.dart';
import 'all_day_events.dart';
import 'multi_date_header.dart';
Expand Down Expand Up @@ -43,7 +44,7 @@ class TimetableHeader<E extends Event> extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: 72,
height: context.timetableTheme?.totalDateIndicatorHeight ?? 72,
child: MultiDateHeader(controller: controller),
),
AllDayEvents<E>(
Expand Down
9 changes: 3 additions & 6 deletions lib/src/header/weekday_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'date_indicator.dart';
class WeekdayIndicator extends StatelessWidget {
const WeekdayIndicator(this.date, {Key key}) : super(key: key);

static final _pattern = LocalDatePattern.createWithCurrentCulture('ddd');

final LocalDate date;

@override
Expand All @@ -20,6 +18,8 @@ class WeekdayIndicator extends StatelessWidget {
final timetableTheme = context.timetableTheme;

final states = DateIndicator.statesFor(date);
final pattern = timetableTheme?.weekDayIndicatorPattern?.resolve(states) ??
LocalDatePattern.createWithCurrentCulture('ddd');
final decoration =
timetableTheme?.weekDayIndicatorDecoration?.resolve(states) ??
BoxDecoration();
Expand All @@ -35,10 +35,7 @@ class WeekdayIndicator extends StatelessWidget {
decoration: decoration,
child: Padding(
padding: EdgeInsets.all(8),
child: Text(
_pattern.format(date),
style: textStyle,
),
child: Text(pattern.format(date), style: textStyle),
),
);
}
Expand Down
31 changes: 31 additions & 0 deletions lib/src/theme.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:time_machine/time_machine.dart';
import 'package:time_machine/time_machine_text_patterns.dart';

import 'timetable.dart';

Expand All @@ -9,8 +11,11 @@ class TimetableThemeData {
this.primaryColor,
this.weekIndicatorDecoration,
this.weekIndicatorTextStyle,
this.totalDateIndicatorHeight,
this.weekDayIndicatorPattern,
this.weekDayIndicatorDecoration,
this.weekDayIndicatorTextStyle,
this.dateIndicatorPattern,
this.dateIndicatorDecoration,
this.dateIndicatorTextStyle,
this.allDayEventHeight,
Expand Down Expand Up @@ -43,6 +48,20 @@ class TimetableThemeData {
/// [TextStyle] used to display the current week number.
final TextStyle weekIndicatorTextStyle;

/// Total (combined) height of both the day-of-week- and
/// date-of-month-indicators.
///
/// > **Note:** This will soon be determined automatically based on the actual
/// > height.
@experimental
final double totalDateIndicatorHeight;

/// [LocalDatePattern] for formatting the day-of-week.
///
/// See also:
/// - [dateIndicatorTextStyle] for a list of possible states.
final MaterialStateProperty<LocalDatePattern> weekDayIndicatorPattern;

/// [Decoration] to show around the day-of-week-indicator.
///
/// See also:
Expand All @@ -55,6 +74,12 @@ class TimetableThemeData {
/// - [dateIndicatorTextStyle] for a list of possible states.
final MaterialStateProperty<TextStyle> weekDayIndicatorTextStyle;

/// [LocalDatePattern] for formatting the date (of month).
///
/// See also:
/// - [dateIndicatorTextStyle] for a list of possible states.
final MaterialStateProperty<LocalDatePattern> dateIndicatorPattern;

/// [Decoration] to show around the date (of month) indicator.
///
/// See also:
Expand Down Expand Up @@ -119,8 +144,11 @@ class TimetableThemeData {
primaryColor,
weekIndicatorDecoration,
weekIndicatorTextStyle,
totalDateIndicatorHeight,
weekDayIndicatorPattern,
weekDayIndicatorDecoration,
weekDayIndicatorTextStyle,
dateIndicatorPattern,
dateIndicatorDecoration,
dateIndicatorTextStyle,
allDayEventHeight,
Expand Down Expand Up @@ -148,8 +176,11 @@ class TimetableThemeData {
other.primaryColor == primaryColor &&
other.weekIndicatorDecoration == weekIndicatorDecoration &&
other.weekIndicatorTextStyle == weekIndicatorTextStyle &&
other.totalDateIndicatorHeight == totalDateIndicatorHeight &&
other.weekDayIndicatorPattern == weekDayIndicatorPattern &&
other.weekDayIndicatorDecoration == weekDayIndicatorDecoration &&
other.weekDayIndicatorTextStyle == weekDayIndicatorTextStyle &&
other.dateIndicatorPattern == dateIndicatorPattern &&
other.dateIndicatorDecoration == dateIndicatorDecoration &&
other.dateIndicatorTextStyle == dateIndicatorTextStyle &&
other.allDayEventHeight == allDayEventHeight &&
Expand Down

0 comments on commit edae72d

Please sign in to comment.