Skip to content

Commit

Permalink
User Interface Enhancements (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Mar 29, 2024
1 parent dc3607f commit 53ff568
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 93 deletions.
28 changes: 28 additions & 0 deletions lib/base/util/places_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/util/string_parser.dart';
import 'package:campus_flutter/placesComponent/model/cafeterias/opening_hours.dart';
import 'package:flutter/material.dart';

class PlacesUtil {
static Widget? openingHours(
(bool, OpeningHour?)? openingHours,
DateTime? dateTime,
BuildContext context,
) {
if (openingHours != null && dateTime != null) {
final dayString = StringParser.getDayString(dateTime, context);
return Padding(
padding: EdgeInsets.only(left: context.padding),
child: Text(
context.localizations.open(
dayString,
openingHours.$2!.start,
openingHours.$2!.end,
),
),
);
} else {
return null;
}
}
}
10 changes: 10 additions & 0 deletions lib/base/util/string_parser.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/base/extensions/date_time.dart';
import 'package:flutter/material.dart';
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -57,4 +58,13 @@ class StringParser {
static int? optStringToOptInt(String? number) {
return number != null ? int.tryParse(number) : null;
}

static String getDayString(DateTime dateTime, BuildContext context) {
final today = DateTime.now();
if (dateTime.isAtSameDay(today)) {
return context.localizations.today;
} else {
return DateFormat.EEEE(context.localizations.localeName).format(dateTime);
}
}
}
17 changes: 2 additions & 15 deletions lib/placesComponent/model/cafeterias/cafeteria.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/extensions/date_time.dart';
import 'package:campus_flutter/placesComponent/model/cafeterias/opening_hours.dart';
import 'package:campus_flutter/searchComponent/model/comparison_token.dart';
import 'package:campus_flutter/searchComponent/protocols/searchable.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:json_annotation/json_annotation.dart';

part 'cafeteria.g.dart';
Expand Down Expand Up @@ -55,8 +51,8 @@ class Cafeteria extends Searchable {
return name;
}

(bool, OpeningHour?) openingHoursForDate(DateTime dateTime) {
switch (dateTime.weekday) {
(bool, OpeningHour?) openingHoursForDate(DateTime? dateTime) {
switch (dateTime?.weekday) {
case 1:
return (true, openingHours?.mon);
case 2:
Expand All @@ -72,15 +68,6 @@ class Cafeteria extends Searchable {
}
}

String getDayString(DateTime dateTime, BuildContext context) {
final today = DateTime.now();
if (dateTime.isAtSameDay(today)) {
return context.localizations.today;
} else {
return DateFormat.EEEE(context.localizations.localeName).format(dateTime);
}
}

@override
@JsonKey(includeFromJson: false, includeToJson: false)
List<ComparisonToken> get comparisonTokens => [
Expand Down
18 changes: 9 additions & 9 deletions lib/placesComponent/viewModels/cafeterias_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ class CafeteriasViewModel {
} else {
LocationService.getLastKnown().then(
(position) => _getClosestCafeteria(position, value.$2),
onError: (error) {
widgetCafeteria.addError(error);
fetchCafeteriaMenu(forcedRefresh, value.$2.first).then(
(menu) => widgetCafeteria.add(
(value.$2.first, menu.firstOrNull),
),
onError: (error) => widgetCafeteria.addError(error),
);
},
onError: (error) => fetchCafeteriaMenu(
forcedRefresh,
value.$2.first,
).then(
(menu) => widgetCafeteria.add(
(value.$2.first, menu.firstOrNull),
),
onError: (error) => widgetCafeteria.addError(error),
),
);
}
},
Expand Down
85 changes: 36 additions & 49 deletions lib/placesComponent/views/cafeterias/cafeteria_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/util/directions_launcher.dart';
import 'package:campus_flutter/base/util/info_row.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/util/places_util.dart';
import 'package:campus_flutter/placesComponent/model/cafeterias/cafeteria.dart';
import 'package:campus_flutter/placesComponent/model/cafeterias/opening_hours.dart';
import 'package:campus_flutter/placesComponent/viewModels/cafeterias_viewmodel.dart';
Expand All @@ -17,6 +18,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:syncfusion_flutter_core/theme.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';

class CafeteriaScaffold extends ConsumerWidget {
Expand Down Expand Up @@ -137,13 +139,11 @@ class CafeteriaView extends ConsumerStatefulWidget {

class _CafeteriaViewState extends ConsumerState<CafeteriaView> {
late DateTime selectedDate;
late (bool, OpeningHour?) openingHours;

@override
void initState() {
final today = DateTime.now();
selectedDate = DateTime(today.year, today.month, today.day);
openingHours = widget.cafeteria.openingHoursForDate(today);
super.initState();
}

Expand All @@ -163,35 +163,12 @@ class _CafeteriaViewState extends ConsumerState<CafeteriaView> {
],
);
} else {
return Column(
children: [
if (openingHours.$2 != null && openingHours.$1)
_openingTimes(openingHours, context),
_pickerAndSlider(false),
],
);
return _pickerAndSlider(false);
}
},
);
}

Widget _openingTimes(
(bool, OpeningHour?) openingHours,
BuildContext context,
) {
if (!openingHours.$1) {
return Text(context.localizations.closedToday);
} else {
return Text(
context.localizations.open(
widget.cafeteria.getDayString(DateTime.now(), context),
openingHours.$2!.start,
openingHours.$2!.end,
),
);
}
}

List<Widget> _mapAndDirections() {
return [
MapWidget.fullPadding(
Expand Down Expand Up @@ -244,14 +221,24 @@ class _CafeteriaViewState extends ConsumerState<CafeteriaView> {
element.date.isAfter(selectedDate),
),
);
return Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.all(context.padding),
child: SizedBox(
height: 80,
final Widget? openingHoursWidget = PlacesUtil.openingHours(
widget.cafeteria.openingHoursForDate(selectedDate),
selectedDate,
context,
);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (openingHoursWidget != null) openingHoursWidget,
Padding(
padding: EdgeInsets.all(context.padding),
child: SizedBox(
height: 80,
child: SfDateRangePickerTheme(
data: const SfDateRangePickerThemeData(
headerBackgroundColor: Colors.transparent,
backgroundColor: Colors.transparent,
),
child: SfDateRangePicker(
headerHeight: 0,
toggleDaySelection: false,
Expand All @@ -275,24 +262,24 @@ class _CafeteriaViewState extends ConsumerState<CafeteriaView> {
),
),
),
if (todayMeals.isNotEmpty)
Expanded(
child: DishGridView(
dishes: todayMeals,
isLandscape: isLandscape,
//inverted: true,
),
),
if (todayMeals.isNotEmpty)
Expanded(
child: DishGridView(
dishes: todayMeals,
isLandscape: isLandscape,
//inverted: true,
),
if (todayMeals.isEmpty)
Center(
child: Text(
context.localizations.noEntriesFound(
context.localizations.mealPlans,
),
),
if (todayMeals.isEmpty)
Center(
child: Text(
context.localizations.noEntriesFound(
context.localizations.mealPlans,
),
),
],
),
),
],
);
}
} else if (snapshot.hasError) {
Expand Down
26 changes: 6 additions & 20 deletions lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/routing/routes.dart';
import 'package:campus_flutter/base/util/places_util.dart';
import 'package:campus_flutter/homeComponent/widgetComponent/views/preference_selection_view.dart';
import 'package:campus_flutter/homeComponent/widgetComponent/views/widget_frame_view.dart';
import 'package:campus_flutter/placesComponent/model/cafeterias/cafeteria.dart';
Expand Down Expand Up @@ -70,32 +71,17 @@ class _CafeteriaWidgetViewState extends ConsumerState<CafeteriaWidgetView> {
),
],
),
subtitle: _openingHours(snapshot.data),
subtitle: PlacesUtil.openingHours(
snapshot.data?.$1.openingHoursForDate(snapshot.data?.$2?.date),
snapshot.data?.$2!.date,
context,
),
child: _dynamicContent(snapshot),
);
},
);
}

Widget? _openingHours((Cafeteria, CafeteriaMenu?)? value) {
if (value != null && value.$2 != null) {
final openingHours = value.$1.openingHoursForDate(value.$2!.date);
final dayString = value.$1.getDayString(value.$2!.date, context);
return Padding(
padding: EdgeInsets.only(left: context.padding),
child: Text(
context.localizations.open(
dayString,
openingHours.$2!.start,
openingHours.$2!.end,
),
),
);
} else {
return null;
}
}

Widget _dynamicContent(AsyncSnapshot<(Cafeteria, CafeteriaMenu?)?> snapshot) {
if (snapshot.hasData) {
final dishes =
Expand Down

0 comments on commit 53ff568

Please sign in to comment.