FBLA24/fbla_ui/lib/shared/utils.dart
2024-06-26 21:35:47 -05:00

326 lines
7.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pdf/widgets.dart' as pw;
enum DataTypeBusiness {
logo,
name,
description,
type,
website,
contactName,
contactEmail,
contactPhone,
notes,
}
enum DataTypeJob {
businessName,
name,
description,
type,
offerType,
wage,
link,
}
enum BusinessType {
food,
shop,
outdoors,
manufacturing,
entertainment,
other,
}
enum JobType {
retail,
customerService,
foodService,
finance, // unused
healthcare, // unused
education,
maintenance,
manufacturing,
other,
}
enum OfferType { job, internship, apprenticeship }
class JobListing {
int? id;
int? businessId;
String name;
String description;
JobType? type;
OfferType? offerType;
String? wage;
String? link;
JobListing({
this.id,
this.businessId,
required this.name,
required this.description,
this.type,
this.offerType,
this.wage,
this.link,
});
factory JobListing.copy(JobListing input) {
return JobListing(
id: input.id,
businessId: input.businessId,
name: input.name,
description: input.description,
type: input.type,
offerType: input.offerType,
wage: input.wage,
link: input.link,
);
}
}
class Business {
int id;
String? name;
String? description;
BusinessType? type;
String? website;
String? contactName;
String? contactEmail;
String? contactPhone;
String? notes;
String locationName;
String? locationAddress;
List<JobListing>? listings;
Business(
{required this.id,
required this.name,
required this.description,
this.website,
this.type,
this.contactName,
this.contactEmail,
this.contactPhone,
this.notes,
required this.locationName,
this.locationAddress,
this.listings});
factory Business.fromJson(Map<String, dynamic> json) {
List<JobListing>? listings;
if (json['listings'] != null) {
listings = [];
for (int i = 0; i < json['listings'].length; i++) {
listings.add(JobListing(
id: json['listings'][i]['id'],
businessId: json['listings'][i]['businessId'],
name: json['listings'][i]['name'],
description: json['listings'][i]['description'],
type: JobType.values.byName(json['listings'][i]['type']),
wage: json['listings'][i]['wage'],
link: json['listings'][i]['link'],
offerType:
OfferType.values.byName(json['listings'][i]['offerType'])));
}
}
return Business(
id: json['id'],
name: json['name'],
description: json['description'],
type: json['type'] != null
? BusinessType.values.byName(json['type'])
: null,
website: json['website'],
contactName: json['contactName'],
contactEmail: json['contactEmail'],
contactPhone: json['contactPhone'],
notes: json['notes'],
locationName: json['locationName'],
locationAddress: json['locationAddress'],
listings: listings);
}
factory Business.copy(Business input) {
return Business(
id: input.id,
name: input.name,
description: input.description,
website: input.website,
contactName: input.contactName,
contactEmail: input.contactEmail,
contactPhone: input.contactPhone,
notes: input.notes,
locationName: input.locationName,
locationAddress: input.locationAddress,
listings: input.listings);
}
}
IconData getIconFromBusinessType(BusinessType type) {
switch (type) {
case BusinessType.food:
return Icons.restaurant;
case BusinessType.shop:
return Icons.store;
case BusinessType.outdoors:
return Icons.forest;
case BusinessType.manufacturing:
return Icons.factory;
case BusinessType.entertainment:
return Icons.live_tv;
case BusinessType.other:
return Icons.business;
}
}
IconData getIconFromJobType(JobType type) {
switch (type) {
case JobType.retail:
return Icons.shopping_bag;
case JobType.customerService:
return Icons.support_agent;
case JobType.foodService:
return Icons.restaurant;
case JobType.finance:
return Icons.paid;
case JobType.healthcare:
return Icons.medical_services;
case JobType.education:
return Icons.school;
case JobType.maintenance:
return Icons.handyman;
case JobType.manufacturing:
return Icons.factory;
case JobType.other:
return Icons.work;
}
}
pw.IconData getPwIconFromBusinessType(BusinessType type) {
switch (type) {
case BusinessType.food:
return const pw.IconData(0xe56c);
case BusinessType.shop:
return const pw.IconData(0xea12);
case BusinessType.outdoors:
return const pw.IconData(0xea99);
case BusinessType.manufacturing:
return const pw.IconData(0xebbc);
case BusinessType.entertainment:
return const pw.IconData(0xe639);
case BusinessType.other:
return const pw.IconData(0xe0af);
}
}
pw.IconData getPwIconFromJobType(JobType type) {
switch (type) {
case JobType.retail:
return const pw.IconData(0xf1cc);
case JobType.customerService:
return const pw.IconData(0xf0e2);
case JobType.foodService:
return const pw.IconData(0xe56c);
case JobType.finance:
return const pw.IconData(0xf041);
case JobType.healthcare:
return const pw.IconData(0xf109);
case JobType.education:
return const pw.IconData(0xe80c);
case JobType.maintenance:
return const pw.IconData(0xf10b);
case JobType.manufacturing:
return const pw.IconData(0xebbc);
case JobType.other:
return const pw.IconData(0xe8f9);
}
}
String getNameFromBusinessType(BusinessType type) {
switch (type) {
case BusinessType.food:
return 'Food Related';
case BusinessType.shop:
return 'Shops';
case BusinessType.outdoors:
return 'Outdoors';
case BusinessType.manufacturing:
return 'Manufacturing';
case BusinessType.entertainment:
return 'Entertainment';
case BusinessType.other:
return 'Other';
}
}
String getNameFromJobType(JobType type) {
switch (type) {
case JobType.retail:
return 'Retail';
case JobType.customerService:
return 'Customer Service';
case JobType.foodService:
return 'Food Service';
case JobType.finance:
return 'Finance';
case JobType.healthcare:
return 'Healthcare';
case JobType.education:
return 'Education';
case JobType.maintenance:
return 'Maintenance';
case JobType.manufacturing:
return 'Manufacturing';
case JobType.other:
return 'Other';
}
}
String getNameFromOfferType(OfferType type) {
switch (type) {
case OfferType.job:
return 'Job';
case OfferType.internship:
return 'Internship';
case OfferType.apprenticeship:
return 'Apprenticeship';
}
}
String getLetterFromOfferType(OfferType type) {
switch (type) {
case OfferType.job:
return 'J';
case OfferType.internship:
return 'I';
case OfferType.apprenticeship:
return 'A';
}
}
Color getColorFromOfferType(OfferType type) {
switch (type) {
case OfferType.job:
return Colors.blue;
case OfferType.internship:
return Colors.green.shade800;
case OfferType.apprenticeship:
return Colors.red;
}
}
IconData getIconFromThemeMode(ThemeMode theme) {
switch (theme) {
case ThemeMode.dark:
return Icons.dark_mode;
case ThemeMode.light:
return Icons.light_mode;
case ThemeMode.system:
return Icons.brightness_4;
}
}