Skip to content

Commit

Permalink
Refactor helper functions in calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras committed Jul 28, 2023
1 parent a2a53aa commit 7f4ac36
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
29 changes: 7 additions & 22 deletions uni/lib/view/calendar/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:timelines/timelines.dart';
import 'package:uni/model/entities/calendar_event.dart';
import 'package:uni/model/providers/lazy/calendar_provider.dart';
import 'package:uni/view/calendar/widgets/calendar_tile.dart';
import 'package:uni/view/common_widgets/page_title.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/common_widgets/request_dependent_widget_builder.dart';
Expand All @@ -20,7 +21,9 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
Widget getBody(BuildContext context) {
return LazyConsumer<CalendarProvider>(
builder: (context, calendarProvider) => ListView(children: [
_getPageTitle(),
Container(
padding: const EdgeInsets.only(bottom: 6.0),
child: const PageTitle(name: 'Calendário Escolar')),
RequestDependentWidgetBuilder(
status: calendarProvider.status,
builder: () =>
Expand All @@ -32,12 +35,6 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
]));
}

Widget _getPageTitle() {
return Container(
padding: const EdgeInsets.only(bottom: 6.0),
child: const PageTitle(name: 'Calendário Escolar'));
}

Widget getTimeline(BuildContext context, List<CalendarEvent> calendar) {
return FixedTimeline.tileBuilder(
theme: TimelineTheme.of(context).copyWith(
Expand All @@ -50,21 +47,9 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
),
builder: TimelineTileBuilder.fromStyle(
contentsAlign: ContentsAlign.alternating,
contentsBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(24.0),
child: Text(calendar[index].name,
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(fontWeight: FontWeight.w500)),
),
oppositeContentsBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(24.0),
child: Text(calendar[index].date,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontStyle: FontStyle.italic,
)),
),
contentsBuilder: (_, index) => CalendarTile(text: calendar[index].name),
oppositeContentsBuilder: (_, index) =>
CalendarTile(text: calendar[index].date, isOposite: true),
itemCount: calendar.length,
),
);
Expand Down
24 changes: 24 additions & 0 deletions uni/lib/view/calendar/widgets/calendar_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';

class CalendarTile extends StatelessWidget {
final String text;
final bool isOposite;
const CalendarTile({Key? key, required this.text, this.isOposite = false})
: super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(24.0),
child: Text(text,
style: !isOposite
? Theme.of(context)
.textTheme
.titleLarge
?.copyWith(fontWeight: FontWeight.w500)
: Theme.of(context).textTheme.titleMedium?.copyWith(
fontStyle: FontStyle.italic,
)),
);
}
}

0 comments on commit 7f4ac36

Please sign in to comment.