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

Add location support #44

Merged
merged 3 commits into from
Nov 22, 2022
Merged
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
1 change: 1 addition & 0 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class _HomeScreenState extends State<HomeScreen> {
.map(
(schedule) => ScheduleCard(
name: schedule.value.name,
location: schedule.value.location,
backgroundColor:
HexColor.fromHex(schedule.value.color),
onPressed: () {
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Schedule {
String get name => schedule["name"];
String get shortName => schedule["shortName"];
String get color => schedule["color"];
String get timezone => schedule["timezone"];
String get location => schedule["location"];

Map<String, dynamic> get periodSchedule =>
schedule["schedule"] as Map<String, dynamic>;
Expand Down
18 changes: 14 additions & 4 deletions lib/utils/schedule_variant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import 'schedule.dart';
class ScheduleVariant {
String name;
String color;
String timezone;
String location;
List<ScheduleVariantItem> variants;

ScheduleVariant({
required this.name,
required this.color,
required this.timezone,
required this.location,
required this.variants,
});
}
Expand All @@ -35,11 +39,15 @@ class VariantOrSchedule {
'One of the parameters must be provided',
);

String get name =>
type == Schedule ? schedule!.schedule["name"] : variant!.name;
String get name => type == Schedule ? schedule!.name : variant!.name;

String get color =>
type == Schedule ? schedule!.schedule["color"] : variant!.color;
String get color => type == Schedule ? schedule!.color : variant!.color;

String get timezone =>
type == Schedule ? schedule!.timezone : variant!.timezone;

String get location =>
type == Schedule ? schedule!.location : variant!.location;

String get comparableName =>
name.toLowerCase().replaceFirst("a ", "").replaceFirst("the", "").trim();
Expand Down Expand Up @@ -127,6 +135,8 @@ Map<String, VariantOrSchedule> generateScheduleListWithVariants(
name: schedules[variants[id]!.first]["name"]
.replaceAll(RegExp(r"\s\(.*\)"), ""),
color: schedules[variants[id]!.first]["color"],
timezone: schedules[variants[id]!.first]["timezone"],
location: schedules[variants[id]!.first]["location"],
variants: variants[id]!
.map(
(id) => ScheduleVariantItem(
Expand Down
33 changes: 27 additions & 6 deletions lib/widgets/schedule_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class ScheduleCard extends StatelessWidget {
const ScheduleCard({
Key? key,
required this.name,
this.location,
required this.backgroundColor,
required this.onPressed,
}) : super(key: key);

final String name;
final String? location;
final Color backgroundColor;
final VoidCallback onPressed;

Expand All @@ -34,12 +36,31 @@ class ScheduleCard extends StatelessWidget {
0,
15,
),
child: Text(
name,
style: const TextStyle(
fontSize: 16.0,
),
),
child: location == null
? Text(
name,
style: const TextStyle(
fontSize: 16.0,
),
)
: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
name,
style: const TextStyle(
fontSize: 16.0,
),
),
Text(
location!,
style: const TextStyle(
fontSize: 12.0,
),
)
],
),
),
),
const SizedBox(
Expand Down