0.2 fixes
This commit is contained in:
parent
4517ec3078
commit
03abc1191d
@ -1,14 +1,17 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:argon2/argon2.dart';
|
import 'package:argon2/argon2.dart';
|
||||||
import 'dart:io';
|
|
||||||
import 'package:postgres/postgres.dart';
|
import 'package:postgres/postgres.dart';
|
||||||
|
|
||||||
|
// Set these to the desired username and password of your user
|
||||||
String username = 'admin';
|
String username = 'admin';
|
||||||
String password = 'password';
|
String password = 'adminPassword';
|
||||||
|
|
||||||
var r = Random.secure();
|
var r = Random.secure();
|
||||||
String randomSalt = String.fromCharCodes(List.generate(32, (index) => r.nextInt(33) + 89));
|
String randomSalt =
|
||||||
|
String.fromCharCodes(List.generate(32, (index) => r.nextInt(33) + 89));
|
||||||
final salt = randomSalt.toBytesLatin1();
|
final salt = randomSalt.toBytesLatin1();
|
||||||
|
|
||||||
var parameters = Argon2Parameters(
|
var parameters = Argon2Parameters(
|
||||||
@ -37,10 +40,8 @@ Future<void> main() async {
|
|||||||
argon2.generateBytes(passwordBytes, result);
|
argon2.generateBytes(passwordBytes, result);
|
||||||
var resultHex = result.toHexString();
|
var resultHex = result.toHexString();
|
||||||
|
|
||||||
postgres.query(
|
postgres.query('''
|
||||||
'''
|
|
||||||
INSERT INTO public.users (username, password_hash, salt)
|
INSERT INTO public.users (username, password_hash, salt)
|
||||||
VALUES ('$username', '$resultHex', '$randomSalt')
|
VALUES ('$username', '$resultHex', '$randomSalt')
|
||||||
'''
|
''');
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,8 @@ enum BusinessType {
|
|||||||
|
|
||||||
enum JobType { cashier, server, mechanic, other }
|
enum JobType { cashier, server, mechanic, other }
|
||||||
|
|
||||||
|
enum OfferType { job, internship, apprenticeship }
|
||||||
|
|
||||||
class Business {
|
class Business {
|
||||||
int id;
|
int id;
|
||||||
String name;
|
String name;
|
||||||
@ -84,6 +86,7 @@ class JobListing {
|
|||||||
JobType type;
|
JobType type;
|
||||||
String? wage;
|
String? wage;
|
||||||
String? link;
|
String? link;
|
||||||
|
OfferType offerType;
|
||||||
|
|
||||||
JobListing(
|
JobListing(
|
||||||
{this.id,
|
{this.id,
|
||||||
@ -92,7 +95,8 @@ class JobListing {
|
|||||||
required this.description,
|
required this.description,
|
||||||
required this.type,
|
required this.type,
|
||||||
this.wage,
|
this.wage,
|
||||||
this.link});
|
this.link,
|
||||||
|
required this.offerType});
|
||||||
|
|
||||||
factory JobListing.fromJson(Map<String, dynamic> json) {
|
factory JobListing.fromJson(Map<String, dynamic> json) {
|
||||||
bool typeValid = true;
|
bool typeValid = true;
|
||||||
@ -110,7 +114,7 @@ class JobListing {
|
|||||||
type: typeValid ? JobType.values.byName(json['type']) : JobType.other,
|
type: typeValid ? JobType.values.byName(json['type']) : JobType.other,
|
||||||
wage: json['wage'],
|
wage: json['wage'],
|
||||||
link: json['link'],
|
link: json['link'],
|
||||||
);
|
offerType: OfferType.values.byName(json['offerType']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,12 +170,15 @@ void main() async {
|
|||||||
app.get('/fbla-api/businessdata/overview/jobs', (Request request) async {
|
app.get('/fbla-api/businessdata/overview/jobs', (Request request) async {
|
||||||
print('business overview request received');
|
print('business overview request received');
|
||||||
|
|
||||||
var filters = request.url.queryParameters['filters']?.split(',') ??
|
var typeFilters = request.url.queryParameters['typeFilters']?.split(',') ??
|
||||||
JobType.values.asNameMap().keys;
|
JobType.values.asNameMap().keys;
|
||||||
|
var offerFilters =
|
||||||
|
request.url.queryParameters['offerFilters']?.split(',') ??
|
||||||
|
OfferType.values.asNameMap().keys;
|
||||||
|
|
||||||
Map<String, dynamic> output = {};
|
Map<String, dynamic> output = {};
|
||||||
|
|
||||||
for (int i = 0; i < filters.length; i++) {
|
for (int i = 0; i < typeFilters.length; i++) {
|
||||||
var postgresResult = (await postgres.query('''
|
var postgresResult = (await postgres.query('''
|
||||||
SELECT json_agg(
|
SELECT json_agg(
|
||||||
json_build_object(
|
json_build_object(
|
||||||
@ -181,6 +188,7 @@ void main() async {
|
|||||||
'contactEmail', b."contactEmail",
|
'contactEmail', b."contactEmail",
|
||||||
'contactPhone', b."contactPhone",
|
'contactPhone', b."contactPhone",
|
||||||
'locationName', b."locationName",
|
'locationName', b."locationName",
|
||||||
|
'locationAddress', b."locationAddress",
|
||||||
'listings', (
|
'listings', (
|
||||||
SELECT json_agg(
|
SELECT json_agg(
|
||||||
json_build_object(
|
json_build_object(
|
||||||
@ -188,22 +196,23 @@ void main() async {
|
|||||||
'name', l.name,
|
'name', l.name,
|
||||||
'description', l.description,
|
'description', l.description,
|
||||||
'type', l.type,
|
'type', l.type,
|
||||||
|
'offerType', l."offerType",
|
||||||
'wage', l.wage,
|
'wage', l.wage,
|
||||||
'link', l.link
|
'link', l.link
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
FROM listings l
|
FROM listings l
|
||||||
WHERE l."businessId" = b.id AND l.type = '${filters.elementAt(i)}'
|
WHERE l."businessId" = b.id AND l.type = '${typeFilters.elementAt(i)}' AND l."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
FROM businesses b
|
FROM businesses b
|
||||||
WHERE b.id IN (SELECT "businessId" FROM public.listings WHERE type='${filters.elementAt(i)}')
|
WHERE b.id IN (SELECT "businessId" FROM public.listings WHERE type='${typeFilters.elementAt(i)}' AND "offerType" IN (${offerFilters.map((element) => "'$element'").join(',')}))
|
||||||
GROUP BY b.id;
|
GROUP BY b.id;
|
||||||
'''));
|
'''));
|
||||||
|
|
||||||
if (postgresResult.isNotEmpty) {
|
if (postgresResult.isNotEmpty) {
|
||||||
output.addAll({filters.elementAt(i): postgresResult[0][0]});
|
output.addAll({typeFilters.elementAt(i): postgresResult[0][0]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +243,8 @@ void main() async {
|
|||||||
'website', website,
|
'website', website,
|
||||||
'contactEmail', "contactEmail",
|
'contactEmail', "contactEmail",
|
||||||
'contactPhone', "contactPhone",
|
'contactPhone', "contactPhone",
|
||||||
'locationName', "locationName"
|
'locationName', "locationName",
|
||||||
|
'locationAddress', "locationAddress"
|
||||||
)
|
)
|
||||||
) FROM public.businesses WHERE type='${filters.elementAt(i)}'
|
) FROM public.businesses WHERE type='${filters.elementAt(i)}'
|
||||||
'''))[0][0];
|
'''))[0][0];
|
||||||
@ -302,7 +312,8 @@ void main() async {
|
|||||||
'description', l.description,
|
'description', l.description,
|
||||||
'type', l.type,
|
'type', l.type,
|
||||||
'wage', l.wage,
|
'wage', l.wage,
|
||||||
'link', l.link
|
'link', l.link,
|
||||||
|
'offerType', l."offerType"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
@ -348,25 +359,11 @@ void main() async {
|
|||||||
'contactPhone', b."contactPhone",
|
'contactPhone', b."contactPhone",
|
||||||
'notes', b.notes,
|
'notes', b.notes,
|
||||||
'locationName', b."locationName",
|
'locationName', b."locationName",
|
||||||
'locationAddress', b."locationAddress",
|
'locationAddress', b."locationAddress"
|
||||||
'listings', CASE
|
|
||||||
WHEN COUNT(l.id) = 0 THEN 'null'
|
|
||||||
ELSE json_agg(
|
|
||||||
json_build_object(
|
|
||||||
'id', l.id,
|
|
||||||
'businessId', l."businessId",
|
|
||||||
'name', l.name,
|
|
||||||
'description', l.description,
|
|
||||||
'type', l.type,
|
|
||||||
'wage', l.wage,
|
|
||||||
'link', l.link
|
|
||||||
)
|
|
||||||
)
|
|
||||||
END
|
|
||||||
)
|
)
|
||||||
FROM businesses b
|
FROM businesses b
|
||||||
LEFT JOIN listings l ON b.id = l."businessId"
|
LEFT JOIN listings l ON b.id = l."businessId"
|
||||||
WHERE b.id IN ${'$filters'.replaceAll('[', '(').replaceAll(']', ')')}
|
WHERE b.id IN (${filters.join(',')})
|
||||||
GROUP BY b.id;
|
GROUP BY b.id;
|
||||||
'''));
|
'''));
|
||||||
|
|
||||||
@ -413,8 +410,8 @@ void main() async {
|
|||||||
print('business logo request received');
|
print('business logo request received');
|
||||||
|
|
||||||
var logo = File('logos/$logoId.png');
|
var logo = File('logos/$logoId.png');
|
||||||
|
try {
|
||||||
List<int> content = logo.readAsBytesSync();
|
List<int> content = logo.readAsBytesSync();
|
||||||
|
|
||||||
return Response.ok(
|
return Response.ok(
|
||||||
content,
|
content,
|
||||||
headers: {
|
headers: {
|
||||||
@ -422,6 +419,16 @@ void main() async {
|
|||||||
'Content-Type': 'image/png'
|
'Content-Type': 'image/png'
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print('Error reading logo!');
|
||||||
|
return Response.notFound(
|
||||||
|
'logo not found',
|
||||||
|
headers: {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Content-Type': 'image/png'
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
app.post('/fbla-api/createbusiness', (Request request) async {
|
app.post('/fbla-api/createbusiness', (Request request) async {
|
||||||
print('create business request received');
|
print('create business request received');
|
||||||
@ -475,8 +482,8 @@ void main() async {
|
|||||||
JobListing listing = JobListing.fromJson(json);
|
JobListing listing = JobListing.fromJson(json);
|
||||||
|
|
||||||
await postgres.query('''
|
await postgres.query('''
|
||||||
INSERT INTO listings ("businessId", name, description, type, wage, link)
|
INSERT INTO listings ("businessId", name, description, type, wage, link, "offerType")
|
||||||
VALUES ('${listing.businessId}', '${listing.name.replaceAll("'", "''")}', '${listing.description.replaceAll("'", "''")}', '${listing.type.name}', '${listing.wage ?? 'NULL'}', '${listing.link?.replaceAll("'", "''") ?? 'NULL'}')
|
VALUES ('${listing.businessId}', '${listing.name.replaceAll("'", "''")}', '${listing.description.replaceAll("'", "''")}', '${listing.type.name}', '${listing.wage ?? 'NULL'}', '${listing.link?.replaceAll("'", "''") ?? 'NULL'}', '${listing.offerType.name}')
|
||||||
'''
|
'''
|
||||||
.replaceAll("'null'", 'NULL'));
|
.replaceAll("'null'", 'NULL'));
|
||||||
|
|
||||||
@ -619,7 +626,7 @@ void main() async {
|
|||||||
|
|
||||||
await postgres.query('''
|
await postgres.query('''
|
||||||
UPDATE listings SET
|
UPDATE listings SET
|
||||||
"businessId" = ${listing.businessId}, name = '${listing.name.replaceAll("'", "''")}'::text, description = '${listing.description.replaceAll("'", "''")}'::text, type = '${listing.type.name}'::text, wage = '${listing.wage ?? 'NULL'}'::text, link = '${listing.link?.replaceAll("'", "''") ?? 'NULL'}'::text WHERE
|
"businessId" = ${listing.businessId}, name = '${listing.name.replaceAll("'", "''")}'::text, description = '${listing.description.replaceAll("'", "''")}'::text, type = '${listing.type.name}'::text, wage = '${listing.wage ?? 'NULL'}'::text, link = '${listing.link?.replaceAll("'", "''") ?? 'NULL'}'::text, "offerType"='${listing.offerType.name}'::text WHERE
|
||||||
id = ${listing.id};
|
id = ${listing.id};
|
||||||
'''
|
'''
|
||||||
.replaceAll("'null'", 'NULL'));
|
.replaceAll("'null'", 'NULL'));
|
||||||
|
|||||||
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
# The following line activates a set of recommended lints for Flutter apps,
|
# The following line activates a set of recommended lints for Flutter apps,
|
||||||
# packages, and plugins designed to encourage good coding practices.
|
# packages, and plugins designed to encourage good coding practices.
|
||||||
|
analyzer:
|
||||||
|
errors:
|
||||||
|
use_build_context_synchronously: ignore
|
||||||
include: package:flutter_lints/flutter.yaml
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
linter:
|
linter:
|
||||||
|
|||||||
@ -20,6 +20,7 @@ class Home extends StatefulWidget {
|
|||||||
|
|
||||||
class _HomeState extends State<Home> {
|
class _HomeState extends State<Home> {
|
||||||
Set<JobType> jobTypeFilters = <JobType>{};
|
Set<JobType> jobTypeFilters = <JobType>{};
|
||||||
|
Set<OfferType> offerTypeFilters = <OfferType>{};
|
||||||
Set<BusinessType> businessTypeFilters = <BusinessType>{};
|
Set<BusinessType> businessTypeFilters = <BusinessType>{};
|
||||||
String searchQuery = '';
|
String searchQuery = '';
|
||||||
late Future refreshBusinessDataOverviewJobFuture;
|
late Future refreshBusinessDataOverviewJobFuture;
|
||||||
@ -65,12 +66,16 @@ class _HomeState extends State<Home> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateOverviewBusinessesJobsCallback(
|
Future<void> _updateOverviewBusinessesJobsCallback(
|
||||||
Set<JobType>? newFilters) async {
|
Set<JobType>? newJobTypeFilters,
|
||||||
if (newFilters != null) {
|
Set<OfferType>? newOfferTypeFilters) async {
|
||||||
jobTypeFilters = Set.from(newFilters);
|
if (newJobTypeFilters != null) {
|
||||||
|
jobTypeFilters = Set.from(newJobTypeFilters);
|
||||||
}
|
}
|
||||||
var refreshedData =
|
if (newOfferTypeFilters != null) {
|
||||||
fetchBusinessDataOverviewJobs(typeFilters: jobTypeFilters.toList());
|
offerTypeFilters = Set.from(newOfferTypeFilters);
|
||||||
|
}
|
||||||
|
var refreshedData = fetchBusinessDataOverviewJobs(
|
||||||
|
typeFilters: jobTypeFilters, offerFilters: offerTypeFilters);
|
||||||
await refreshedData;
|
await refreshedData;
|
||||||
setState(() {
|
setState(() {
|
||||||
refreshBusinessDataOverviewJobFuture = refreshedData;
|
refreshBusinessDataOverviewJobFuture = refreshedData;
|
||||||
@ -100,7 +105,7 @@ class _HomeState extends State<Home> {
|
|||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
edgeOffset: 145,
|
edgeOffset: 145,
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
_updateOverviewBusinessesJobsCallback(null);
|
_updateOverviewBusinessesJobsCallback(null, null);
|
||||||
_updateOverviewBusinessesBusinessCallback(null);
|
_updateOverviewBusinessesBusinessCallback(null);
|
||||||
},
|
},
|
||||||
child: widescreen
|
child: widescreen
|
||||||
@ -186,7 +191,6 @@ class _HomeState extends State<Home> {
|
|||||||
children: [
|
children: [
|
||||||
NavigationRail(
|
NavigationRail(
|
||||||
selectedIndex: currentPageIndex,
|
selectedIndex: currentPageIndex,
|
||||||
groupAlignment: -1,
|
|
||||||
indicatorColor:
|
indicatorColor:
|
||||||
Theme.of(context).colorScheme.primary.withOpacity(0.5),
|
Theme.of(context).colorScheme.primary.withOpacity(0.5),
|
||||||
trailing: Expanded(
|
trailing: Expanded(
|
||||||
@ -219,7 +223,6 @@ class _HomeState extends State<Home> {
|
|||||||
),
|
),
|
||||||
if (loggedIn)
|
if (loggedIn)
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
child: Icon(Icons.add),
|
|
||||||
heroTag: 'Homepage',
|
heroTag: 'Homepage',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (currentPageIndex == 0) {
|
if (currentPageIndex == 0) {
|
||||||
@ -236,6 +239,7 @@ class _HomeState extends State<Home> {
|
|||||||
const CreateEditJobListing()));
|
const CreateEditJobListing()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
child: const Icon(Icons.add),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -314,7 +318,7 @@ class _ContentPane extends StatelessWidget {
|
|||||||
updateOverviewBusinessesBusinessCallback;
|
updateOverviewBusinessesBusinessCallback;
|
||||||
final void Function() themeCallback;
|
final void Function() themeCallback;
|
||||||
final Future refreshBusinessDataOverviewJobFuture;
|
final Future refreshBusinessDataOverviewJobFuture;
|
||||||
final Future<void> Function(Set<JobType>)
|
final Future<void> Function(Set<JobType>?, Set<OfferType>?)
|
||||||
updateOverviewBusinessesJobsCallback;
|
updateOverviewBusinessesJobsCallback;
|
||||||
final int currentPageIndex;
|
final int currentPageIndex;
|
||||||
final void Function(bool) updateLoggedIn;
|
final void Function(bool) updateLoggedIn;
|
||||||
|
|||||||
@ -69,32 +69,53 @@ class _MainAppState extends State<MainApp> {
|
|||||||
title: 'Job Link',
|
title: 'Job Link',
|
||||||
themeMode: themeMode,
|
themeMode: themeMode,
|
||||||
darkTheme: ThemeData(
|
darkTheme: ThemeData(
|
||||||
|
scaffoldBackgroundColor: const Color(0xFF121212),
|
||||||
colorScheme: ColorScheme.dark(
|
colorScheme: ColorScheme.dark(
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
primary: Colors.blue.shade700,
|
primary: Colors.blue.shade700,
|
||||||
onPrimary: Colors.white,
|
onPrimary: Colors.white,
|
||||||
secondary: Colors.blue.shade900,
|
secondary: Colors.blue.shade900,
|
||||||
surface: const Color.fromARGB(255, 31, 31, 31),
|
surface: const Color.fromARGB(255, 31, 31, 31),
|
||||||
surfaceContainer: const Color.fromARGB(255, 40, 40, 40),
|
surfaceContainer: const Color.fromARGB(255, 46, 46, 46),
|
||||||
tertiary: Colors.green.shade900,
|
tertiary: Colors.green.shade900,
|
||||||
),
|
),
|
||||||
iconTheme: const IconThemeData(color: Colors.white),
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
inputDecorationTheme: const InputDecorationTheme(),
|
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
|
// border: OutlineInputBorder(),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey.withOpacity(0.1),
|
||||||
|
labelStyle: const TextStyle(color: Colors.grey),
|
||||||
|
),
|
||||||
|
dropdownMenuTheme: const DropdownMenuThemeData(
|
||||||
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
|
filled: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
|
scaffoldBackgroundColor: Colors.grey.shade300,
|
||||||
colorScheme: ColorScheme.light(
|
colorScheme: ColorScheme.light(
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
primary: Colors.blue.shade700,
|
primary: Colors.blue.shade700,
|
||||||
onPrimary: Colors.white,
|
onPrimary: Colors.white,
|
||||||
secondary: Colors.blue.shade200,
|
secondary: Colors.blue.shade300,
|
||||||
surface: Colors.grey.shade200,
|
surface: Colors.grey.shade100,
|
||||||
surfaceContainer: Colors.grey.shade300,
|
surfaceContainer: Colors.grey.shade200,
|
||||||
tertiary: Colors.green,
|
tertiary: Colors.green,
|
||||||
),
|
),
|
||||||
iconTheme: const IconThemeData(color: Colors.black),
|
iconTheme: const IconThemeData(color: Colors.black),
|
||||||
inputDecorationTheme:
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
const InputDecorationTheme(border: UnderlineInputBorder()),
|
// border: OutlineInputBorder(),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.blue.withOpacity(0.1),
|
||||||
|
labelStyle: const TextStyle(color: Colors.grey),
|
||||||
|
),
|
||||||
|
dropdownMenuTheme: const DropdownMenuThemeData(
|
||||||
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
|
filled: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: Home(themeCallback: _switchTheme, initialPage: widget.initialPage),
|
home: Home(themeCallback: _switchTheme, initialPage: widget.initialPage),
|
||||||
|
|||||||
@ -105,10 +105,15 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView _detailBody(Business business) {
|
Widget _detailBody(Business business) {
|
||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
// Title, logo, desc, website
|
// Title, logo, desc, website
|
||||||
|
Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 800,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 4.0),
|
padding: const EdgeInsets.only(top: 4.0),
|
||||||
child: Card(
|
child: Card(
|
||||||
@ -116,25 +121,30 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
|
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||||
title: Text(business.name!,
|
title: Text(business.name!,
|
||||||
textAlign: TextAlign.left,
|
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 24, fontWeight: FontWeight.bold)),
|
fontSize: 24, fontWeight: FontWeight.bold)),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
business.description!,
|
business.description!,
|
||||||
textAlign: TextAlign.left,
|
|
||||||
),
|
),
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.only(bottom: 8, left: 16),
|
||||||
leading: ClipRRect(
|
leading: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
child: Image.network('$apiAddress/logos/${business.id}',
|
child: Image.network(
|
||||||
|
'$apiAddress/logos/${business.id}',
|
||||||
width: 48,
|
width: 48,
|
||||||
height: 48, errorBuilder: (BuildContext context,
|
height: 48, errorBuilder: (BuildContext context,
|
||||||
Object exception, StackTrace? stackTrace) {
|
Object exception, StackTrace? stackTrace) {
|
||||||
return Icon(getIconFromBusinessType(business.type!),
|
return Icon(
|
||||||
|
getIconFromBusinessType(
|
||||||
|
business.type ?? BusinessType.other),
|
||||||
size: 48);
|
size: 48);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (business.website != null)
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.link),
|
leading: const Icon(Icons.link),
|
||||||
title: const Text('Website'),
|
title: const Text('Website'),
|
||||||
@ -145,7 +155,8 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
.replaceAll('www.', ''),
|
.replaceAll('www.', ''),
|
||||||
style: const TextStyle(color: Colors.blue)),
|
style: const TextStyle(color: Colors.blue)),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(Uri.parse(business.website!));
|
launchUrl(
|
||||||
|
Uri.parse('https://${business.website}'));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -156,8 +167,9 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
if (business.listings != null)
|
if (business.listings != null)
|
||||||
Card(
|
Card(
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child:
|
child: Column(
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 16, top: 4),
|
padding: const EdgeInsets.only(left: 16, top: 4),
|
||||||
child: _GetListingsTitle(business)),
|
child: _GetListingsTitle(business)),
|
||||||
@ -172,7 +184,8 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 16.0, top: 8.0),
|
padding:
|
||||||
|
const EdgeInsets.only(left: 16.0, top: 8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
business.contactName!,
|
business.contactName!,
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
@ -194,7 +207,8 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
Theme.of(context).colorScheme.surface,
|
Theme.of(context).colorScheme.surface,
|
||||||
title: Text('Contact ${business.contactName}'),
|
title:
|
||||||
|
Text('Contact ${business.contactName}'),
|
||||||
content: Text(
|
content: Text(
|
||||||
'Would you like to call or text ${business.contactName}?'),
|
'Would you like to call or text ${business.contactName}?'),
|
||||||
actions: [
|
actions: [
|
||||||
@ -222,7 +236,8 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
leading: const Icon(Icons.email),
|
leading: const Icon(Icons.email),
|
||||||
title: Text(business.contactEmail!),
|
title: Text(business.contactEmail!),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(Uri.parse('mailto:${business.contactEmail}'));
|
launchUrl(
|
||||||
|
Uri.parse('mailto:${business.contactEmail}'));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -237,7 +252,7 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
subtitle: Text(business.locationAddress!),
|
subtitle: Text(business.locationAddress!),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(Uri.parse(Uri.encodeFull(
|
launchUrl(Uri.parse(Uri.encodeFull(
|
||||||
'https://www.google.com/maps/search/?api=1&query=${business.locationName}')));
|
'https://www.google.com/maps/search/?api=1&query=${business.locationName} ${business.locationAddress}')));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -248,12 +263,17 @@ class _CreateBusinessDetailState extends State<BusinessDetail> {
|
|||||||
leading: const Icon(Icons.notes),
|
leading: const Icon(Icons.notes),
|
||||||
title: const Text(
|
title: const Text(
|
||||||
'Additional Notes',
|
'Additional Notes',
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
style: TextStyle(
|
||||||
|
fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
subtitle: Text(business.notes!),
|
subtitle: Text(business.notes!),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -213,6 +213,7 @@ class _BusinessesOverviewState extends State<BusinessesOverview> {
|
|||||||
: Theme.of(context).colorScheme.onSurface,
|
: Theme.of(context).colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
selectedChips = Set.from(businessTypeFilters);
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
@ -338,9 +339,9 @@ class _BusinessDisplayPanelState extends State<BusinessDisplayPanel> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BusinessHeader> headers = [];
|
List<_BusinessHeader> headers = [];
|
||||||
for (BusinessType businessType in widget.groupedBusinesses.keys) {
|
for (BusinessType businessType in widget.groupedBusinesses.keys) {
|
||||||
headers.add(BusinessHeader(
|
headers.add(_BusinessHeader(
|
||||||
businessType: businessType,
|
businessType: businessType,
|
||||||
widescreen: widget.widescreen,
|
widescreen: widget.widescreen,
|
||||||
businesses: widget.groupedBusinesses[businessType]!));
|
businesses: widget.groupedBusinesses[businessType]!));
|
||||||
@ -351,23 +352,22 @@ class _BusinessDisplayPanelState extends State<BusinessDisplayPanel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BusinessHeader extends StatefulWidget {
|
class _BusinessHeader extends StatefulWidget {
|
||||||
final BusinessType businessType;
|
final BusinessType businessType;
|
||||||
final List<Business> businesses;
|
final List<Business> businesses;
|
||||||
final bool widescreen;
|
final bool widescreen;
|
||||||
|
|
||||||
const BusinessHeader({
|
const _BusinessHeader({
|
||||||
super.key,
|
|
||||||
required this.businessType,
|
required this.businessType,
|
||||||
required this.businesses,
|
required this.businesses,
|
||||||
required this.widescreen,
|
required this.widescreen,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<BusinessHeader> createState() => _BusinessHeaderState();
|
State<_BusinessHeader> createState() => _BusinessHeaderState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BusinessHeaderState extends State<BusinessHeader> {
|
class _BusinessHeaderState extends State<_BusinessHeader> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverStickyHeader(
|
return SliverStickyHeader(
|
||||||
@ -391,7 +391,8 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
getIconFromBusinessType(widget.businessType),
|
getIconFromBusinessType(widget.businessType),
|
||||||
color: Theme.of(context).colorScheme.onPrimary,
|
color: Theme.of(context).colorScheme.onPrimary,
|
||||||
)),
|
)),
|
||||||
Text(getNameFromBusinessType(widget.businessType)),
|
Text(getNameFromBusinessType(widget.businessType),
|
||||||
|
style: TextStyle(color: Theme.of(context).colorScheme.onPrimary)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -491,6 +492,7 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
|
if (business.website != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.link),
|
icon: const Icon(Icons.link),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -501,7 +503,7 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
icon: const Icon(Icons.location_on),
|
icon: const Icon(Icons.location_on),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
launchUrl(Uri.parse(Uri.encodeFull(
|
launchUrl(Uri.parse(Uri.encodeFull(
|
||||||
'https://www.google.com/maps/search/?api=1&query=${business.locationName}')));
|
'https://www.google.com/maps/search/?api=1&query=${business.locationName} ${business.locationAddress}')));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (business.contactPhone != null)
|
if (business.contactPhone != null)
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import 'package:fbla_ui/shared/utils.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import '../shared/global_vars.dart';
|
||||||
|
|
||||||
class CreateEditBusiness extends StatefulWidget {
|
class CreateEditBusiness extends StatefulWidget {
|
||||||
final Business? inputBusiness;
|
final Business? inputBusiness;
|
||||||
|
|
||||||
@ -23,15 +25,14 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
late TextEditingController _notesController;
|
late TextEditingController _notesController;
|
||||||
late TextEditingController _locationNameController;
|
late TextEditingController _locationNameController;
|
||||||
late TextEditingController _locationAddressController;
|
late TextEditingController _locationAddressController;
|
||||||
|
late bool widescreen;
|
||||||
// late TextEditingController _businessTypeController;
|
|
||||||
|
|
||||||
Business business = Business(
|
Business business = Business(
|
||||||
id: 0,
|
id: 0,
|
||||||
name: 'Business',
|
name: 'Business',
|
||||||
description: 'Add details about the business below.',
|
description: 'Add details about the business below.',
|
||||||
type: null,
|
type: null,
|
||||||
website: '',
|
website: null,
|
||||||
contactName: null,
|
contactName: null,
|
||||||
contactEmail: null,
|
contactEmail: null,
|
||||||
contactPhone: null,
|
contactPhone: null,
|
||||||
@ -56,8 +57,8 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
_descriptionController = TextEditingController();
|
_descriptionController = TextEditingController();
|
||||||
}
|
}
|
||||||
_websiteController = TextEditingController(
|
_websiteController = TextEditingController(
|
||||||
text: business.website!
|
text: business.website
|
||||||
.replaceAll('https://', '')
|
?.replaceAll('https://', '')
|
||||||
.replaceAll('http://', '')
|
.replaceAll('http://', '')
|
||||||
.replaceAll('www.', ''));
|
.replaceAll('www.', ''));
|
||||||
_contactNameController = TextEditingController(text: business.contactName);
|
_contactNameController = TextEditingController(text: business.contactName);
|
||||||
@ -76,6 +77,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
widescreen = MediaQuery.sizeOf(context).width >= widescreenWidth;
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: !_isLoading,
|
canPop: !_isLoading,
|
||||||
onPopInvoked: _handlePop,
|
onPopInvoked: _handlePop,
|
||||||
@ -87,8 +89,10 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
? Text('Edit ${widget.inputBusiness?.name}', maxLines: 1)
|
? Text('Edit ${widget.inputBusiness?.name}', maxLines: 1)
|
||||||
: const Text('Add New Business'),
|
: const Text('Add New Business'),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: !widescreen
|
||||||
child: _isLoading
|
? FloatingActionButton.extended(
|
||||||
|
label: const Text('Save'),
|
||||||
|
icon: _isLoading
|
||||||
? const Padding(
|
? const Padding(
|
||||||
padding: EdgeInsets.all(16.0),
|
padding: EdgeInsets.all(16.0),
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
@ -98,54 +102,10 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
)
|
)
|
||||||
: const Icon(Icons.save),
|
: const Icon(Icons.save),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (business.type == null) {
|
await _saveBusiness(context);
|
||||||
setState(() {
|
|
||||||
dropDownErrorText = 'Business type is required';
|
|
||||||
});
|
|
||||||
formKey.currentState!.validate();
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
dropDownErrorText = null;
|
|
||||||
});
|
|
||||||
if (formKey.currentState!.validate()) {
|
|
||||||
formKey.currentState?.save();
|
|
||||||
setState(() {
|
|
||||||
_isLoading = true;
|
|
||||||
});
|
|
||||||
String? result;
|
|
||||||
if (widget.inputBusiness != null) {
|
|
||||||
result = await editBusiness(business);
|
|
||||||
} else {
|
|
||||||
result = await createBusiness(business);
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
_isLoading = false;
|
|
||||||
});
|
|
||||||
if (result != null) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
width: 400,
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
content: Text(result)));
|
|
||||||
} else {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => const MainApp()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: const Text('Check field inputs!'),
|
|
||||||
width: 200,
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
|
: null,
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
@ -154,26 +114,25 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
|
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||||
title: Text(business.name!,
|
title: Text(business.name!,
|
||||||
textAlign: TextAlign.left,
|
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 24, fontWeight: FontWeight.bold)),
|
fontSize: 24, fontWeight: FontWeight.bold)),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
business.description!,
|
business.description!,
|
||||||
textAlign: TextAlign.left,
|
|
||||||
),
|
),
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.only(bottom: 8, left: 16),
|
||||||
leading: ClipRRect(
|
leading: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
|
'$apiAddress/logos/${business.id}',
|
||||||
width: 48,
|
width: 48,
|
||||||
height: 48,
|
height: 48, errorBuilder: (BuildContext context,
|
||||||
'https://logo.clearbit.com/${business.website}',
|
|
||||||
errorBuilder: (BuildContext context,
|
|
||||||
Object exception, StackTrace? stackTrace) {
|
Object exception, StackTrace? stackTrace) {
|
||||||
return Icon(
|
return Icon(
|
||||||
getIconFromBusinessType(business.type != null
|
getIconFromBusinessType(
|
||||||
? business.type!
|
business.type ?? BusinessType.other),
|
||||||
: BusinessType.other),
|
|
||||||
size: 48);
|
size: 48);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@ -183,7 +142,10 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0),
|
top: 8.0,
|
||||||
|
bottom: 8.0,
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _nameController,
|
controller: _nameController,
|
||||||
autovalidateMode:
|
autovalidateMode:
|
||||||
@ -210,7 +172,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0),
|
bottom: 8.0, left: 8.0, right: 8.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _descriptionController,
|
controller: _descriptionController,
|
||||||
autovalidateMode:
|
autovalidateMode:
|
||||||
@ -247,44 +209,42 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
keyboardType: TextInputType.url,
|
keyboardType: TextInputType.url,
|
||||||
onChanged: (inputUrl) {
|
onChanged: (inputUrl) {
|
||||||
business.website = Uri.encodeFull(inputUrl);
|
business.website = Uri.encodeFull(inputUrl);
|
||||||
|
if (inputUrl.trim().isEmpty) {
|
||||||
|
business.website = null;
|
||||||
|
} else {
|
||||||
if (!business.website!
|
if (!business.website!
|
||||||
.contains('http://') &&
|
.contains('http://') &&
|
||||||
!business.website!
|
!business.website!
|
||||||
.contains('https://')) {
|
.contains('https://')) {
|
||||||
business.website =
|
business.website =
|
||||||
'https://${business.website}';
|
'https://${business.website!.trim()}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onTapOutside: (PointerDownEvent event) {
|
onTapOutside: (PointerDownEvent event) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Website (required)',
|
labelText: 'Website',
|
||||||
),
|
),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value != null &&
|
if (value != null &&
|
||||||
!RegExp(r'(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:\/[^\/\s]*)*')
|
!RegExp(r'(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:/[^/\s]*)*')
|
||||||
.hasMatch(value)) {
|
.hasMatch(value)) {
|
||||||
return 'Enter a valid Website';
|
return 'Enter a valid Website';
|
||||||
}
|
}
|
||||||
if (value != null && value.trim().isEmpty) {
|
|
||||||
return 'Website is required';
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0, bottom: 8.0),
|
left: 8.0, right: 8.0, bottom: 16.0),
|
||||||
child: Row(
|
child: DropdownMenu<BusinessType>(
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
const Text('Type of Business',
|
|
||||||
style: TextStyle(fontSize: 16)),
|
|
||||||
DropdownMenu<BusinessType>(
|
|
||||||
initialSelection: business.type,
|
initialSelection: business.type,
|
||||||
|
// width: 776,
|
||||||
label: const Text('Business Type'),
|
label: const Text('Business Type'),
|
||||||
errorText: dropDownErrorText,
|
errorText: dropDownErrorText,
|
||||||
dropdownMenuEntries: [
|
dropdownMenuEntries: [
|
||||||
@ -292,8 +252,8 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
in BusinessType.values)
|
in BusinessType.values)
|
||||||
DropdownMenuEntry(
|
DropdownMenuEntry(
|
||||||
value: type,
|
value: type,
|
||||||
label: getNameFromBusinessType(
|
label:
|
||||||
type)),
|
getNameFromBusinessType(type)),
|
||||||
],
|
],
|
||||||
onSelected: (inputType) {
|
onSelected: (inputType) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -302,7 +262,6 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -380,7 +339,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
// ),
|
// ),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0, bottom: 8.0),
|
left: 8.0, right: 8.0, bottom: 16.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _contactNameController,
|
controller: _contactNameController,
|
||||||
onSaved: (inputText) {
|
onSaved: (inputText) {
|
||||||
@ -405,7 +364,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0, bottom: 8.0),
|
left: 8.0, right: 8.0, bottom: 16.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _contactPhoneController,
|
controller: _contactPhoneController,
|
||||||
inputFormatters: [PhoneFormatter()],
|
inputFormatters: [PhoneFormatter()],
|
||||||
@ -439,7 +398,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0, bottom: 8.0),
|
left: 8.0, right: 8.0, bottom: 16.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _contactEmailController,
|
controller: _contactEmailController,
|
||||||
keyboardType: TextInputType.emailAddress,
|
keyboardType: TextInputType.emailAddress,
|
||||||
@ -482,7 +441,7 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 8.0, right: 8.0, bottom: 8.0),
|
left: 8.0, right: 8.0, bottom: 16.0),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _locationNameController,
|
controller: _locationNameController,
|
||||||
onChanged: (inputName) {
|
onChanged: (inputName) {
|
||||||
@ -558,9 +517,33 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
if (!widescreen)
|
||||||
|
const SizedBox(
|
||||||
height: 75,
|
height: 75,
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.topRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: FilledButton(
|
||||||
|
child: const Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: 8.0, right: 8.0, bottom: 8.0),
|
||||||
|
child: Icon(Icons.save),
|
||||||
|
),
|
||||||
|
Text('Save'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
await _saveBusiness(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -582,6 +565,53 @@ class _CreateEditBusinessState extends State<CreateEditBusiness> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _saveBusiness(BuildContext context) async {
|
||||||
|
if (business.type == null) {
|
||||||
|
setState(() {
|
||||||
|
dropDownErrorText = 'Business type is required';
|
||||||
|
});
|
||||||
|
formKey.currentState!.validate();
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
dropDownErrorText = null;
|
||||||
|
});
|
||||||
|
if (formKey.currentState!.validate()) {
|
||||||
|
formKey.currentState?.save();
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
String? result;
|
||||||
|
if (widget.inputBusiness != null) {
|
||||||
|
result = await editBusiness(business);
|
||||||
|
} else {
|
||||||
|
result = await createBusiness(business);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
if (result != null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
width: 400,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
content: Text(result)));
|
||||||
|
} else {
|
||||||
|
Navigator.pushReplacement(context,
|
||||||
|
MaterialPageRoute(builder: (context) => const MainApp()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: const Text('Check field inputs!'),
|
||||||
|
width: 200,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
shape:
|
||||||
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PhoneFormatter extends TextInputFormatter {
|
class PhoneFormatter extends TextInputFormatter {
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import 'package:fbla_ui/main.dart';
|
|
||||||
import 'package:fbla_ui/shared/api_logic.dart';
|
import 'package:fbla_ui/shared/api_logic.dart';
|
||||||
|
import 'package:fbla_ui/shared/global_vars.dart';
|
||||||
import 'package:fbla_ui/shared/utils.dart';
|
import 'package:fbla_ui/shared/utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
import '../main.dart';
|
||||||
|
|
||||||
class CreateEditJobListing extends StatefulWidget {
|
class CreateEditJobListing extends StatefulWidget {
|
||||||
final JobListing? inputJobListing;
|
final JobListing? inputJobListing;
|
||||||
final Business? inputBusiness;
|
final Business? inputBusiness;
|
||||||
@ -21,9 +23,10 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
late TextEditingController _descriptionController;
|
late TextEditingController _descriptionController;
|
||||||
late TextEditingController _wageController;
|
late TextEditingController _wageController;
|
||||||
late TextEditingController _linkController;
|
late TextEditingController _linkController;
|
||||||
List nameMapping = [];
|
List<Map<String, dynamic>> nameMapping = [];
|
||||||
String? typeDropdownErrorText;
|
String? typeDropdownErrorText;
|
||||||
String? businessDropdownErrorText;
|
String? businessDropdownErrorText;
|
||||||
|
late bool widescreen;
|
||||||
|
|
||||||
JobListing listing = JobListing(
|
JobListing listing = JobListing(
|
||||||
id: null,
|
id: null,
|
||||||
@ -32,7 +35,8 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
description: 'Add details about the business below.',
|
description: 'Add details about the business below.',
|
||||||
type: null,
|
type: null,
|
||||||
wage: null,
|
wage: null,
|
||||||
link: null);
|
link: null,
|
||||||
|
offerType: null);
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -59,6 +63,7 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
widescreen = MediaQuery.sizeOf(context).width >= widescreenWidth;
|
||||||
if (widget.inputBusiness != null) {
|
if (widget.inputBusiness != null) {
|
||||||
listing.businessId = widget.inputBusiness!.id;
|
listing.businessId = widget.inputBusiness!.id;
|
||||||
}
|
}
|
||||||
@ -73,8 +78,10 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
? Text('Edit ${widget.inputJobListing?.name}', maxLines: 1)
|
? Text('Edit ${widget.inputJobListing?.name}', maxLines: 1)
|
||||||
: const Text('Add New Job Listing'),
|
: const Text('Add New Job Listing'),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: !widescreen
|
||||||
child: _isLoading
|
? FloatingActionButton.extended(
|
||||||
|
label: const Text('Save'),
|
||||||
|
icon: _isLoading
|
||||||
? const Padding(
|
? const Padding(
|
||||||
padding: EdgeInsets.all(16.0),
|
padding: EdgeInsets.all(16.0),
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
@ -84,6 +91,417 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
)
|
)
|
||||||
: const Icon(Icons.save),
|
: const Icon(Icons.save),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
await _saveListing(context);
|
||||||
|
})
|
||||||
|
: null,
|
||||||
|
body: FutureBuilder(
|
||||||
|
future: getBusinessNameMapping,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
if (snapshot.data.runtimeType == String) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(children: [
|
||||||
|
Center(
|
||||||
|
child: Text(snapshot.data,
|
||||||
|
textAlign: TextAlign.center)),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: FilledButton(
|
||||||
|
child: const Text('Retry'),
|
||||||
|
onPressed: () async {
|
||||||
|
var refreshedData = fetchBusinessNames();
|
||||||
|
await refreshedData;
|
||||||
|
setState(() {
|
||||||
|
getBusinessNameMapping = refreshedData;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
nameMapping = snapshot.data;
|
||||||
|
nameMapping.sort((a, b) =>
|
||||||
|
a['name'].toString().compareTo(b['name'].toString()));
|
||||||
|
|
||||||
|
return ListView(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 800,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
titleAlignment:
|
||||||
|
ListTileTitleAlignment.titleHeight,
|
||||||
|
title: Text(listing.name,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold)),
|
||||||
|
subtitle: Text(
|
||||||
|
listing.description,
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.only(
|
||||||
|
bottom: 8, left: 16),
|
||||||
|
leading: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
|
child: Image.network(
|
||||||
|
'$apiAddress/logos/${listing.businessId}',
|
||||||
|
width: 48,
|
||||||
|
height: 48, errorBuilder:
|
||||||
|
(BuildContext context,
|
||||||
|
Object exception,
|
||||||
|
StackTrace? stackTrace) {
|
||||||
|
return Icon(
|
||||||
|
getIconFromJobType(
|
||||||
|
listing.type ?? JobType.other),
|
||||||
|
size: 48);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Business Type Dropdown
|
||||||
|
Card(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Wrap(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 8.0,
|
||||||
|
top: 8.0),
|
||||||
|
child: DropdownMenu<JobType>(
|
||||||
|
initialSelection:
|
||||||
|
listing.type,
|
||||||
|
label: const Text('Job Type'),
|
||||||
|
errorText:
|
||||||
|
typeDropdownErrorText,
|
||||||
|
width: calculateDropdownWidth(
|
||||||
|
context),
|
||||||
|
dropdownMenuEntries: [
|
||||||
|
for (JobType type
|
||||||
|
in JobType.values)
|
||||||
|
DropdownMenuEntry(
|
||||||
|
value: type,
|
||||||
|
label:
|
||||||
|
getNameFromJobType(
|
||||||
|
type))
|
||||||
|
],
|
||||||
|
onSelected: (inputType) {
|
||||||
|
setState(() {
|
||||||
|
listing.type = inputType!;
|
||||||
|
typeDropdownErrorText =
|
||||||
|
null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 8.0,
|
||||||
|
top: 8.0),
|
||||||
|
child: DropdownMenu<OfferType>(
|
||||||
|
initialSelection:
|
||||||
|
listing.offerType,
|
||||||
|
label:
|
||||||
|
const Text('Offer Type'),
|
||||||
|
errorText:
|
||||||
|
typeDropdownErrorText,
|
||||||
|
width: calculateDropdownWidth(
|
||||||
|
context),
|
||||||
|
dropdownMenuEntries: [
|
||||||
|
for (OfferType type
|
||||||
|
in OfferType.values)
|
||||||
|
DropdownMenuEntry(
|
||||||
|
value: type,
|
||||||
|
label:
|
||||||
|
getNameFromOfferType(
|
||||||
|
type))
|
||||||
|
],
|
||||||
|
onSelected: (inputType) {
|
||||||
|
setState(() {
|
||||||
|
listing.offerType =
|
||||||
|
inputType!;
|
||||||
|
typeDropdownErrorText =
|
||||||
|
null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 16.0,
|
||||||
|
top: 8.0),
|
||||||
|
child: DropdownMenu<int>(
|
||||||
|
menuHeight: 300,
|
||||||
|
width: (MediaQuery.sizeOf(context)
|
||||||
|
.width -
|
||||||
|
24) <
|
||||||
|
776
|
||||||
|
? MediaQuery.sizeOf(context)
|
||||||
|
.width -
|
||||||
|
24
|
||||||
|
: 776,
|
||||||
|
errorText:
|
||||||
|
businessDropdownErrorText,
|
||||||
|
initialSelection:
|
||||||
|
widget.inputBusiness?.id,
|
||||||
|
label: const Text(
|
||||||
|
'Offering Business'),
|
||||||
|
dropdownMenuEntries: [
|
||||||
|
for (Map<String, dynamic> map
|
||||||
|
in nameMapping)
|
||||||
|
DropdownMenuEntry(
|
||||||
|
value: map['id']!,
|
||||||
|
label: map['name'])
|
||||||
|
],
|
||||||
|
onSelected: (inputType) {
|
||||||
|
setState(() {
|
||||||
|
listing.businessId =
|
||||||
|
inputType!;
|
||||||
|
businessDropdownErrorText =
|
||||||
|
null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 8.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _nameController,
|
||||||
|
autovalidateMode: AutovalidateMode
|
||||||
|
.onUserInteraction,
|
||||||
|
maxLength: 30,
|
||||||
|
onChanged: (inputName) {
|
||||||
|
setState(() {
|
||||||
|
listing.name = inputName;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onTapOutside:
|
||||||
|
(PointerDownEvent event) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
},
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText:
|
||||||
|
'Job Listing Name (required)',
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null &&
|
||||||
|
value.isEmpty) {
|
||||||
|
return 'Name is required';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 8.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _descriptionController,
|
||||||
|
autovalidateMode: AutovalidateMode
|
||||||
|
.onUserInteraction,
|
||||||
|
maxLength: 500,
|
||||||
|
maxLines: null,
|
||||||
|
onChanged: (inputDesc) {
|
||||||
|
setState(() {
|
||||||
|
listing.description = inputDesc;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onTapOutside:
|
||||||
|
(PointerDownEvent event) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
},
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText:
|
||||||
|
'Job Listing Description (required)',
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null &&
|
||||||
|
value.isEmpty) {
|
||||||
|
return 'Description is required';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 16.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _wageController,
|
||||||
|
onChanged: (input) {
|
||||||
|
setState(() {
|
||||||
|
listing.wage = input;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onTapOutside:
|
||||||
|
(PointerDownEvent event) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
},
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Wage Information',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 16.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _linkController,
|
||||||
|
autovalidateMode: AutovalidateMode
|
||||||
|
.onUserInteraction,
|
||||||
|
keyboardType: TextInputType.url,
|
||||||
|
onChanged: (inputUrl) {
|
||||||
|
if (inputUrl != '') {
|
||||||
|
listing.link =
|
||||||
|
Uri.encodeFull(inputUrl);
|
||||||
|
if (!listing.link!
|
||||||
|
.contains('http://') &&
|
||||||
|
!listing.link!
|
||||||
|
.contains('https://')) {
|
||||||
|
listing.link =
|
||||||
|
'https://${listing.link}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listing.link = null;
|
||||||
|
},
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null &&
|
||||||
|
value.isNotEmpty &&
|
||||||
|
!RegExp(r'(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:/[^/\s]*)*')
|
||||||
|
.hasMatch(value)) {
|
||||||
|
return 'Enter a valid Website';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
onTapOutside:
|
||||||
|
(PointerDownEvent event) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
},
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText:
|
||||||
|
'Additional Information Link',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (!widescreen)
|
||||||
|
const SizedBox(
|
||||||
|
height: 75,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.topRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: FilledButton(
|
||||||
|
child: const Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: 8.0,
|
||||||
|
right: 8.0,
|
||||||
|
bottom: 8.0),
|
||||||
|
child: Icon(Icons.save),
|
||||||
|
),
|
||||||
|
Text('Save'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
await _saveListing(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
|
||||||
|
child: Text(
|
||||||
|
'Error when loading data! Error: ${snapshot.error}'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (snapshot.connectionState ==
|
||||||
|
ConnectionState.waiting) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: const SizedBox(
|
||||||
|
width: 75,
|
||||||
|
height: 75,
|
||||||
|
child: RiveAnimation.asset(
|
||||||
|
'assets/mdev_triangle_loading.riv'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.only(left: 16.0, right: 16.0),
|
||||||
|
child: Text('Error when loading data!'),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double calculateDropdownWidth(BuildContext context) {
|
||||||
|
double screenWidth = MediaQuery.sizeOf(context).width;
|
||||||
|
|
||||||
|
if ((screenWidth - 40) / 2 < 200) {
|
||||||
|
return screenWidth - 24;
|
||||||
|
} else if ((screenWidth - 40) / 2 < 380) {
|
||||||
|
return (screenWidth - 40) / 2;
|
||||||
|
} else {
|
||||||
|
return 380;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handlePop(bool didPop) {
|
||||||
|
if (!didPop) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
width: 400,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
content: Text('Please wait for it to save.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _saveListing(BuildContext context) async {
|
||||||
if (listing.type == null || listing.businessId == null) {
|
if (listing.type == null || listing.businessId == null) {
|
||||||
if (listing.type == null) {
|
if (listing.type == null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -135,336 +553,11 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
|
|||||||
content: const Text('Check field inputs!'),
|
content: const Text('Check field inputs!'),
|
||||||
width: 200,
|
width: 200,
|
||||||
behavior: SnackBarBehavior.floating,
|
behavior: SnackBarBehavior.floating,
|
||||||
shape: RoundedRectangleBorder(
|
shape:
|
||||||
borderRadius: BorderRadius.circular(10)),
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
body: FutureBuilder(
|
|
||||||
future: getBusinessNameMapping,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
if (snapshot.data.runtimeType == String) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Column(children: [
|
|
||||||
Center(
|
|
||||||
child: Text(snapshot.data,
|
|
||||||
textAlign: TextAlign.center)),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: FilledButton(
|
|
||||||
child: const Text('Retry'),
|
|
||||||
onPressed: () async {
|
|
||||||
var refreshedData = fetchBusinessNames();
|
|
||||||
await refreshedData;
|
|
||||||
setState(() {
|
|
||||||
getBusinessNameMapping = refreshedData;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
nameMapping = snapshot.data;
|
|
||||||
|
|
||||||
return ListView(
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: SizedBox(
|
|
||||||
width: 800,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
ListTile(
|
|
||||||
title: Text(listing.name,
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 24,
|
|
||||||
fontWeight: FontWeight.bold)),
|
|
||||||
subtitle: Text(
|
|
||||||
listing.description,
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
),
|
|
||||||
leading: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
|
||||||
child: Image.network(
|
|
||||||
width: 48,
|
|
||||||
height: 48,
|
|
||||||
listing.businessId != null
|
|
||||||
? '$apiAddress/logos/${listing.businessId}'
|
|
||||||
: '',
|
|
||||||
errorBuilder: (BuildContext context,
|
|
||||||
Object exception,
|
|
||||||
StackTrace? stackTrace) {
|
|
||||||
return Icon(
|
|
||||||
getIconFromJobType(
|
|
||||||
listing.type ?? JobType.other,
|
|
||||||
),
|
|
||||||
size: 48);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Business Type Dropdown
|
|
||||||
Card(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0,
|
|
||||||
right: 8.0,
|
|
||||||
bottom: 8.0,
|
|
||||||
top: 8),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
const Text('Type of Job',
|
|
||||||
style:
|
|
||||||
TextStyle(fontSize: 16)),
|
|
||||||
DropdownMenu<JobType>(
|
|
||||||
initialSelection: listing.type,
|
|
||||||
label: const Text('Job Type'),
|
|
||||||
errorText:
|
|
||||||
typeDropdownErrorText,
|
|
||||||
dropdownMenuEntries: [
|
|
||||||
for (JobType type
|
|
||||||
in JobType.values)
|
|
||||||
DropdownMenuEntry(
|
|
||||||
value: type,
|
|
||||||
label:
|
|
||||||
getNameFromJobType(
|
|
||||||
type))
|
|
||||||
],
|
|
||||||
onSelected: (inputType) {
|
|
||||||
setState(() {
|
|
||||||
listing.type = inputType!;
|
|
||||||
typeDropdownErrorText =
|
|
||||||
null;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0,
|
|
||||||
right: 8.0,
|
|
||||||
bottom: 8.0,
|
|
||||||
top: 8),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Business that has the job',
|
|
||||||
style:
|
|
||||||
TextStyle(fontSize: 16)),
|
|
||||||
DropdownMenu<int>(
|
|
||||||
errorText:
|
|
||||||
businessDropdownErrorText,
|
|
||||||
initialSelection:
|
|
||||||
widget.inputBusiness?.id,
|
|
||||||
label: const Text('Business'),
|
|
||||||
dropdownMenuEntries: [
|
|
||||||
for (Map<String, dynamic> map
|
|
||||||
in nameMapping)
|
|
||||||
DropdownMenuEntry(
|
|
||||||
value: map['id']!,
|
|
||||||
label: map['name'])
|
|
||||||
],
|
|
||||||
onSelected: (inputType) {
|
|
||||||
setState(() {
|
|
||||||
listing.businessId =
|
|
||||||
inputType!;
|
|
||||||
businessDropdownErrorText =
|
|
||||||
null;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0, right: 8.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _nameController,
|
|
||||||
autovalidateMode: AutovalidateMode
|
|
||||||
.onUserInteraction,
|
|
||||||
maxLength: 30,
|
|
||||||
onChanged: (inputName) {
|
|
||||||
setState(() {
|
|
||||||
listing.name = inputName;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onTapOutside:
|
|
||||||
(PointerDownEvent event) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText:
|
|
||||||
'Job Listing Name (required)',
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null &&
|
|
||||||
value.isEmpty) {
|
|
||||||
return 'Name is required';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0, right: 8.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _descriptionController,
|
|
||||||
autovalidateMode: AutovalidateMode
|
|
||||||
.onUserInteraction,
|
|
||||||
maxLength: 500,
|
|
||||||
maxLines: null,
|
|
||||||
onChanged: (inputDesc) {
|
|
||||||
setState(() {
|
|
||||||
listing.description = inputDesc;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onTapOutside:
|
|
||||||
(PointerDownEvent event) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText:
|
|
||||||
'Job Listing Description (required)',
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null &&
|
|
||||||
value.isEmpty) {
|
|
||||||
return 'Description is required';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0,
|
|
||||||
right: 8.0,
|
|
||||||
bottom: 8.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _wageController,
|
|
||||||
onChanged: (input) {
|
|
||||||
setState(() {
|
|
||||||
listing.wage = input;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onTapOutside:
|
|
||||||
(PointerDownEvent event) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Wage Information',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8.0,
|
|
||||||
right: 8.0,
|
|
||||||
bottom: 8.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _linkController,
|
|
||||||
autovalidateMode: AutovalidateMode
|
|
||||||
.onUserInteraction,
|
|
||||||
keyboardType: TextInputType.url,
|
|
||||||
onChanged: (inputUrl) {
|
|
||||||
if (inputUrl != '') {
|
|
||||||
listing.link =
|
|
||||||
Uri.encodeFull(inputUrl);
|
|
||||||
if (!listing.link!
|
|
||||||
.contains('http://') &&
|
|
||||||
!listing.link!
|
|
||||||
.contains('https://')) {
|
|
||||||
listing.link =
|
|
||||||
'https://${listing.link}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
listing.link = null;
|
|
||||||
},
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null &&
|
|
||||||
value.isNotEmpty &&
|
|
||||||
!RegExp(r'(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:\/[^\/\s]*)*')
|
|
||||||
.hasMatch(value)) {
|
|
||||||
return 'Enter a valid Website';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onTapOutside:
|
|
||||||
(PointerDownEvent event) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText:
|
|
||||||
'Additional Information Link',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 75,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else if (snapshot.hasError) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
|
|
||||||
child: Text(
|
|
||||||
'Error when loading data! Error: ${snapshot.error}'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (snapshot.connectionState ==
|
|
||||||
ConnectionState.waiting) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: const SizedBox(
|
|
||||||
width: 75,
|
|
||||||
height: 75,
|
|
||||||
child: RiveAnimation.asset(
|
|
||||||
'assets/mdev_triangle_loading.riv'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const Padding(
|
|
||||||
padding: EdgeInsets.only(left: 16.0, right: 16.0),
|
|
||||||
child: Text('Error when loading data!'),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handlePop(bool didPop) {
|
|
||||||
if (!didPop) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
width: 400,
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
content: Text('Please wait for it to save.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,51 +29,45 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView _detailBody(JobListing listing) {
|
Widget _detailBody(JobListing listing) {
|
||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
// Title, logo, desc, website
|
// Title, logo, desc, website
|
||||||
|
Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 800,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 4.0),
|
padding: const EdgeInsets.only(top: 4.0),
|
||||||
child: Card(
|
child: Card(
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
ListTile(
|
||||||
padding: const EdgeInsets.all(16.0),
|
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||||
child: Row(
|
title: Text(listing.name,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
style: const TextStyle(
|
||||||
children: [
|
fontSize: 24, fontWeight: FontWeight.bold)),
|
||||||
Padding(
|
subtitle: Text(
|
||||||
padding: const EdgeInsets.only(right: 16.0),
|
listing.description,
|
||||||
child: ClipRRect(
|
),
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.only(bottom: 8, left: 16),
|
||||||
|
leading: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
'$apiAddress/logos/${listing.businessId}',
|
'$apiAddress/logos/${listing.businessId}',
|
||||||
width: 48,
|
width: 48,
|
||||||
height: 48, errorBuilder: (BuildContext context,
|
height: 48, errorBuilder: (BuildContext context,
|
||||||
Object exception, StackTrace? stackTrace) {
|
Object exception, StackTrace? stackTrace) {
|
||||||
return Icon(getIconFromJobType(listing.type!),
|
return Icon(
|
||||||
|
getIconFromJobType(
|
||||||
|
listing.type ?? JobType.other),
|
||||||
size: 48);
|
size: 48);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(listing.name,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 24, fontWeight: FontWeight.bold)),
|
|
||||||
Text(widget.fromBusiness.name!,
|
|
||||||
style: const TextStyle(fontSize: 16)),
|
|
||||||
Text(
|
|
||||||
listing.description,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (listing.link != null && listing.link != '')
|
if (listing.link != null && listing.link != '')
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.link),
|
leading: const Icon(Icons.link),
|
||||||
@ -85,7 +79,7 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
|
|||||||
.replaceAll('www.', ''),
|
.replaceAll('www.', ''),
|
||||||
style: const TextStyle(color: Colors.blue)),
|
style: const TextStyle(color: Colors.blue)),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(Uri.parse(listing.link!));
|
launchUrl(Uri.parse('https://${listing.link!}'));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -110,7 +104,8 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 16.0, top: 8.0),
|
padding:
|
||||||
|
const EdgeInsets.only(left: 16.0, top: 8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.fromBusiness.contactName!,
|
widget.fromBusiness.contactName!,
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
@ -169,6 +164,10 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,8 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
class JobsOverview extends StatefulWidget {
|
class JobsOverview extends StatefulWidget {
|
||||||
final String searchQuery;
|
final String searchQuery;
|
||||||
final Future refreshJobDataOverviewFuture;
|
final Future refreshJobDataOverviewFuture;
|
||||||
final Future<void> Function(Set<JobType>) updateBusinessesCallback;
|
final Future<void> Function(Set<JobType>?, Set<OfferType>?)
|
||||||
|
updateBusinessesCallback;
|
||||||
final void Function() themeCallback;
|
final void Function() themeCallback;
|
||||||
final void Function(bool) updateLoggedIn;
|
final void Function(bool) updateLoggedIn;
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
bool _isPreviousData = false;
|
bool _isPreviousData = false;
|
||||||
late Map<JobType, List<Business>> overviewBusinesses;
|
late Map<JobType, List<Business>> overviewBusinesses;
|
||||||
Set<JobType> jobTypeFilters = <JobType>{};
|
Set<JobType> jobTypeFilters = <JobType>{};
|
||||||
|
Set<OfferType> offerTypeFilters = <OfferType>{};
|
||||||
String searchQuery = '';
|
String searchQuery = '';
|
||||||
ScrollController controller = ScrollController();
|
ScrollController controller = ScrollController();
|
||||||
bool _extended = true;
|
bool _extended = true;
|
||||||
@ -66,9 +68,15 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setFilters(Set<JobType> filters) async {
|
void _setFilters(Set<JobType>? newJobTypeFilters,
|
||||||
jobTypeFilters = Set.from(filters);
|
Set<OfferType>? newOfferTypeFilters) async {
|
||||||
widget.updateBusinessesCallback(jobTypeFilters);
|
if (newJobTypeFilters != null) {
|
||||||
|
jobTypeFilters = Set.from(newJobTypeFilters);
|
||||||
|
}
|
||||||
|
if (newOfferTypeFilters != null) {
|
||||||
|
offerTypeFilters = Set.from(newOfferTypeFilters);
|
||||||
|
}
|
||||||
|
widget.updateBusinessesCallback(jobTypeFilters, offerTypeFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _scrollListener() {
|
void _scrollListener() {
|
||||||
@ -114,9 +122,8 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
setSearch: _setSearch,
|
setSearch: _setSearch,
|
||||||
searchHintText: 'Search Job Listings',
|
searchHintText: 'Search Job Listings',
|
||||||
themeCallback: widget.themeCallback,
|
themeCallback: widget.themeCallback,
|
||||||
filterIconButton: _filterIconButton(
|
filterIconButton:
|
||||||
jobTypeFilters,
|
_filterIconButton(jobTypeFilters, offerTypeFilters),
|
||||||
),
|
|
||||||
updateLoggedIn: widget.updateLoggedIn,
|
updateLoggedIn: widget.updateLoggedIn,
|
||||||
generatePDF: _generatePDF,
|
generatePDF: _generatePDF,
|
||||||
),
|
),
|
||||||
@ -139,7 +146,7 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
child: const Text('Retry'),
|
child: const Text('Retry'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
widget.updateBusinessesCallback(jobTypeFilters);
|
widget.updateBusinessesCallback(null, null);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -201,45 +208,78 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _filterIconButton(Set<JobType> filters) {
|
Widget _filterIconButton(
|
||||||
Set<JobType> selectedChips = Set.from(filters);
|
Set<JobType> jobTypeFilters, Set<OfferType> offerTypeFilters) {
|
||||||
|
Set<JobType> selectedJobTypeChips = Set.from(jobTypeFilters);
|
||||||
|
Set<OfferType> selectedOfferTypeChips = Set.from(offerTypeFilters);
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.filter_list,
|
Icons.filter_list,
|
||||||
color: filters.isNotEmpty
|
color: jobTypeFilters.isNotEmpty
|
||||||
? Theme.of(context).colorScheme.primary
|
? Theme.of(context).colorScheme.primary
|
||||||
: Theme.of(context).colorScheme.onSurface,
|
: Theme.of(context).colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
selectedJobTypeChips = Set.from(jobTypeFilters);
|
||||||
|
selectedOfferTypeChips = Set.from(offerTypeFilters);
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return StatefulBuilder(
|
return StatefulBuilder(
|
||||||
builder: (BuildContext context, StateSetter setState) {
|
builder: (BuildContext context, StateSetter setState) {
|
||||||
void setDialogState(Set<JobType> newFilters) {
|
void setDialogState(Set<JobType>? newJobTypeFilters,
|
||||||
|
Set<OfferType>? newOfferTypeFilters) {
|
||||||
|
if (newJobTypeFilters != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
filters = newFilters;
|
selectedJobTypeChips = newJobTypeFilters;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (newOfferTypeFilters != null) {
|
||||||
|
setState(() {
|
||||||
|
selectedOfferTypeChips = newOfferTypeFilters;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Padding> chips = [];
|
List<Padding> jobTypeChips = [];
|
||||||
for (var type in JobType.values) {
|
for (JobType type in JobType.values) {
|
||||||
chips.add(Padding(
|
jobTypeChips.add(Padding(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
child: FilterChip(
|
child: FilterChip(
|
||||||
showCheckmark: false,
|
showCheckmark: false,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(20)),
|
borderRadius: BorderRadius.circular(20)),
|
||||||
label: Text(getNameFromJobType(type)),
|
label: Text(getNameFromJobType(type)),
|
||||||
selected: selectedChips.contains(type),
|
selected: selectedJobTypeChips.contains(type),
|
||||||
onSelected: (bool selected) {
|
onSelected: (bool selected) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
selectedChips.add(type);
|
selectedJobTypeChips.add(type);
|
||||||
} else {
|
} else {
|
||||||
selectedChips.remove(type);
|
selectedJobTypeChips.remove(type);
|
||||||
}
|
}
|
||||||
setDialogState(filters);
|
setDialogState(selectedJobTypeChips, null);
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Padding> offerTypeChips = [];
|
||||||
|
for (OfferType type in OfferType.values) {
|
||||||
|
offerTypeChips.add(Padding(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
child: FilterChip(
|
||||||
|
showCheckmark: false,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20)),
|
||||||
|
label: Text(getNameFromOfferType(type)),
|
||||||
|
selected: selectedOfferTypeChips.contains(type),
|
||||||
|
onSelected: (bool selected) {
|
||||||
|
if (selected) {
|
||||||
|
selectedOfferTypeChips.add(type);
|
||||||
|
} else {
|
||||||
|
selectedOfferTypeChips.remove(type);
|
||||||
|
}
|
||||||
|
setDialogState(null, selectedOfferTypeChips);
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -248,30 +288,46 @@ class _JobsOverviewState extends State<JobsOverview> {
|
|||||||
title: const Text('Filter Options'),
|
title: const Text('Filter Options'),
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Text('Job Type Filters:'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
children: chips,
|
children: jobTypeChips,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Text('Offer Type Filters:'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: Wrap(
|
||||||
|
children: offerTypeChips,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Reset'),
|
child: const Text('Reset'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_setFilters(<JobType>{});
|
_setFilters(<JobType>{}, <OfferType>{});
|
||||||
// selectedChips = <BusinessType>{};
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// selectedChips = Set.from(filters);
|
// setDialogState(jobTypeFilters, offerTypeFilters);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Apply'),
|
child: const Text('Apply'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_setFilters(selectedChips);
|
_setFilters(
|
||||||
|
selectedJobTypeChips, selectedOfferTypeChips);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -337,9 +393,9 @@ class _JobDisplayPanelState extends State<JobDisplayPanel> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BusinessHeader> headers = [];
|
List<_JobHeader> headers = [];
|
||||||
for (JobType jobType in widget.jobGroupedBusinesses.keys) {
|
for (JobType jobType in widget.jobGroupedBusinesses.keys) {
|
||||||
headers.add(BusinessHeader(
|
headers.add(_JobHeader(
|
||||||
jobType: jobType,
|
jobType: jobType,
|
||||||
widescreen: widget.widescreen,
|
widescreen: widget.widescreen,
|
||||||
businesses: widget.jobGroupedBusinesses[jobType]!));
|
businesses: widget.jobGroupedBusinesses[jobType]!));
|
||||||
@ -349,23 +405,22 @@ class _JobDisplayPanelState extends State<JobDisplayPanel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BusinessHeader extends StatefulWidget {
|
class _JobHeader extends StatefulWidget {
|
||||||
final JobType jobType;
|
final JobType jobType;
|
||||||
final List<Business> businesses;
|
final List<Business> businesses;
|
||||||
final bool widescreen;
|
final bool widescreen;
|
||||||
|
|
||||||
const BusinessHeader({
|
const _JobHeader({
|
||||||
super.key,
|
|
||||||
required this.jobType,
|
required this.jobType,
|
||||||
required this.businesses,
|
required this.businesses,
|
||||||
required this.widescreen,
|
required this.widescreen,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<BusinessHeader> createState() => _BusinessHeaderState();
|
State<_JobHeader> createState() => _JobHeaderState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BusinessHeaderState extends State<BusinessHeader> {
|
class _JobHeaderState extends State<_JobHeader> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverStickyHeader(
|
return SliverStickyHeader(
|
||||||
@ -389,7 +444,8 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
getIconFromJobType(widget.jobType),
|
getIconFromJobType(widget.jobType),
|
||||||
color: Theme.of(context).colorScheme.onPrimary,
|
color: Theme.of(context).colorScheme.onPrimary,
|
||||||
)),
|
)),
|
||||||
Text(getNameFromJobType(widget.jobType)),
|
Text(getNameFromJobType(widget.jobType),
|
||||||
|
style: TextStyle(color: Theme.of(context).colorScheme.onPrimary)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -451,21 +507,34 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Badge(
|
||||||
|
label: Text(
|
||||||
|
getLetterFromOfferType(
|
||||||
|
business.listings![0].offerType!),
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
|
),
|
||||||
|
largeSize: 26,
|
||||||
|
offset: const Offset(15, -5),
|
||||||
|
textColor: Theme.of(context).colorScheme.onPrimary,
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
child: Image.network('$apiAddress/logos/${business.id}',
|
child: Image.network(
|
||||||
|
'$apiAddress/logos/${business.id}',
|
||||||
height: 48,
|
height: 48,
|
||||||
width: 48, errorBuilder: (BuildContext context,
|
width: 48, errorBuilder: (BuildContext context,
|
||||||
Object exception, StackTrace? stackTrace) {
|
Object exception, StackTrace? stackTrace) {
|
||||||
return Icon(getIconFromBusinessType(business.type!),
|
return Icon(
|
||||||
|
getIconFromJobType(business.listings![0].type!),
|
||||||
size: 48);
|
size: 48);
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
)),
|
)),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
business.listings![0].name,
|
'${business.listings![0].name} (${getNameFromOfferType(business.listings![0].offerType!)})',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 18, fontWeight: FontWeight.bold),
|
fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
@ -559,14 +628,23 @@ class _BusinessHeaderState extends State<BusinessHeader> {
|
|||||||
Widget _businessListItem(Business business, JobType? jobType) {
|
Widget _businessListItem(Business business, JobType? jobType) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: ClipRRect(
|
leading: Badge(
|
||||||
|
label: Text(getLetterFromOfferType(business.listings![0].offerType!)),
|
||||||
|
textColor: Theme.of(context).colorScheme.onPrimary,
|
||||||
|
isLabelVisible: true,
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(3.0),
|
borderRadius: BorderRadius.circular(3.0),
|
||||||
child: Image.network('$apiAddress/logos/${business.id}',
|
child: Image.network('$apiAddress/logos/${business.id}',
|
||||||
height: 24, width: 24, errorBuilder: (BuildContext context,
|
height: 24, width: 24, errorBuilder: (BuildContext context,
|
||||||
Object exception, StackTrace? stackTrace) {
|
Object exception, StackTrace? stackTrace) {
|
||||||
return Icon(getIconFromBusinessType(business.type!));
|
return Icon(
|
||||||
|
getIconFromJobType(business.listings![0].type!),
|
||||||
|
);
|
||||||
})),
|
})),
|
||||||
title: Text(business.listings![0].name),
|
),
|
||||||
|
title: Text(
|
||||||
|
'${business.listings![0].name} (${getNameFromOfferType(business.listings![0].offerType!)})'),
|
||||||
subtitle: Text(business.listings![0].description,
|
subtitle: Text(business.listings![0].description,
|
||||||
maxLines: 2, overflow: TextOverflow.ellipsis),
|
maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import 'package:http/http.dart' as http;
|
|||||||
|
|
||||||
var apiAddress = 'https://homelab.marinodev.com/fbla-api';
|
var apiAddress = 'https://homelab.marinodev.com/fbla-api';
|
||||||
// var apiAddress = 'http://192.168.0.114:8000/fbla-api';
|
// var apiAddress = 'http://192.168.0.114:8000/fbla-api';
|
||||||
|
|
||||||
var client = http.Client();
|
var client = http.Client();
|
||||||
|
|
||||||
Future fetchBusinessData() async {
|
Future fetchBusinessData() async {
|
||||||
@ -50,15 +51,20 @@ Future fetchBusinessNames() async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fetchBusinessDataOverviewJobs({List<JobType>? typeFilters}) async {
|
Future fetchBusinessDataOverviewJobs(
|
||||||
|
{Iterable<JobType>? typeFilters, Iterable<OfferType>? offerFilters}) async {
|
||||||
try {
|
try {
|
||||||
String? typeString =
|
String uriString = '$apiAddress/businessdata/overview/jobs';
|
||||||
typeFilters?.map((jobType) => jobType.name).toList().join(',');
|
if (typeFilters != null && typeFilters.isNotEmpty) {
|
||||||
Uri uri =
|
uriString +=
|
||||||
Uri.parse('$apiAddress/businessdata/overview/jobs?filters=$typeString');
|
'?typeFilters=${typeFilters.map((jobType) => jobType.name).join(',')}';
|
||||||
if (typeFilters == null || typeFilters.isEmpty) {
|
|
||||||
uri = Uri.parse('$apiAddress/businessdata/overview/jobs');
|
|
||||||
}
|
}
|
||||||
|
if (offerFilters != null && offerFilters.isNotEmpty) {
|
||||||
|
uriString +=
|
||||||
|
'?offerFilters=${offerFilters.map((offerType) => offerType.name).join(',')}';
|
||||||
|
}
|
||||||
|
Uri uri = Uri.parse(uriString);
|
||||||
|
|
||||||
var response = await http.get(uri).timeout(const Duration(seconds: 20));
|
var response = await http.get(uri).timeout(const Duration(seconds: 20));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
var decodedResponse = json.decode(response.body);
|
var decodedResponse = json.decode(response.body);
|
||||||
@ -225,6 +231,8 @@ Future createListing(JobListing listing) async {
|
|||||||
"businessId": ${listing.businessId},
|
"businessId": ${listing.businessId},
|
||||||
"name": "${listing.name}",
|
"name": "${listing.name}",
|
||||||
"description": "${listing.description.replaceAll('\n', '\\n')}",
|
"description": "${listing.description.replaceAll('\n', '\\n')}",
|
||||||
|
"type": "${listing.type!.name}",
|
||||||
|
"offerType": "${listing.offerType!.name}",
|
||||||
"wage": "${listing.wage}",
|
"wage": "${listing.wage}",
|
||||||
"link": "${listing.link}"
|
"link": "${listing.link}"
|
||||||
}
|
}
|
||||||
@ -324,6 +332,7 @@ Future editListing(JobListing listing) async {
|
|||||||
"name": "${listing.name}",
|
"name": "${listing.name}",
|
||||||
"description": "${listing.description.replaceAll('\n', '\\n')}",
|
"description": "${listing.description.replaceAll('\n', '\\n')}",
|
||||||
"type": "${listing.type!.name}",
|
"type": "${listing.type!.name}",
|
||||||
|
"offerType": "${listing.offerType!.name}",
|
||||||
"wage": "${listing.wage}",
|
"wage": "${listing.wage}",
|
||||||
"link": "${listing.link}"
|
"link": "${listing.link}"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,68 @@ import 'package:pdf/pdf.dart';
|
|||||||
import 'package:pdf/widgets.dart' as pw;
|
import 'package:pdf/widgets.dart' as pw;
|
||||||
import 'package:printing/printing.dart';
|
import 'package:printing/printing.dart';
|
||||||
|
|
||||||
|
Map<DataTypeBusiness, int> dataTypePriorityBusiness = {
|
||||||
|
DataTypeBusiness.logo: 0,
|
||||||
|
DataTypeBusiness.name: 1,
|
||||||
|
DataTypeBusiness.description: 2,
|
||||||
|
DataTypeBusiness.type: 3,
|
||||||
|
DataTypeBusiness.website: 4,
|
||||||
|
DataTypeBusiness.contactName: 5,
|
||||||
|
DataTypeBusiness.contactEmail: 6,
|
||||||
|
DataTypeBusiness.contactPhone: 7,
|
||||||
|
DataTypeBusiness.notes: 8
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<DataTypeBusiness, String> dataTypeFriendlyBusiness = {
|
||||||
|
DataTypeBusiness.logo: 'Logo',
|
||||||
|
DataTypeBusiness.name: 'Name',
|
||||||
|
DataTypeBusiness.description: 'Description',
|
||||||
|
DataTypeBusiness.type: 'Type',
|
||||||
|
DataTypeBusiness.website: 'Website',
|
||||||
|
DataTypeBusiness.contactName: 'Contact Name',
|
||||||
|
DataTypeBusiness.contactEmail: 'Contact Email',
|
||||||
|
DataTypeBusiness.contactPhone: 'Contact Phone',
|
||||||
|
DataTypeBusiness.notes: 'Notes'
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<DataTypeJob, int> dataTypePriorityJob = {
|
||||||
|
DataTypeJob.businessName: 1,
|
||||||
|
DataTypeJob.name: 2,
|
||||||
|
DataTypeJob.description: 3,
|
||||||
|
DataTypeJob.type: 4,
|
||||||
|
DataTypeJob.offerType: 5,
|
||||||
|
DataTypeJob.wage: 6,
|
||||||
|
DataTypeJob.link: 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<DataTypeJob, String> dataTypeFriendlyJob = {
|
||||||
|
DataTypeJob.businessName: 'Business Name',
|
||||||
|
DataTypeJob.name: 'Job Listing Name',
|
||||||
|
DataTypeJob.description: 'Description',
|
||||||
|
DataTypeJob.type: 'Job Type',
|
||||||
|
DataTypeJob.offerType: 'Offer Type',
|
||||||
|
DataTypeJob.wage: 'Wage Information',
|
||||||
|
DataTypeJob.link: 'Additional Info Link',
|
||||||
|
};
|
||||||
|
|
||||||
|
Set<DataTypeBusiness> sortDataTypesBusiness(Set<DataTypeBusiness> set) {
|
||||||
|
List<DataTypeBusiness> list = set.toList();
|
||||||
|
list.sort((a, b) {
|
||||||
|
return dataTypePriorityBusiness[a]!.compareTo(dataTypePriorityBusiness[b]!);
|
||||||
|
});
|
||||||
|
set = list.toSet();
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<DataTypeJob> sortDataTypesJob(Set<DataTypeJob> set) {
|
||||||
|
List<DataTypeJob> list = set.toList();
|
||||||
|
list.sort((a, b) {
|
||||||
|
return dataTypePriorityJob[a]!.compareTo(dataTypePriorityJob[b]!);
|
||||||
|
});
|
||||||
|
set = list.toSet();
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
class _FilterBusinessDataTypeChips extends StatefulWidget {
|
class _FilterBusinessDataTypeChips extends StatefulWidget {
|
||||||
final Set<DataTypeBusiness> selectedDataTypesBusiness;
|
final Set<DataTypeBusiness> selectedDataTypesBusiness;
|
||||||
|
|
||||||
@ -113,11 +175,13 @@ Future<void> generatePDF(
|
|||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
contentPadding: const EdgeInsets.all(16),
|
||||||
|
scrollable: true,
|
||||||
title: const Text('Export Settings'),
|
title: const Text('Export Settings'),
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 200,
|
|
||||||
child: Column(
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.all(8.0),
|
padding: EdgeInsets.all(8.0),
|
||||||
@ -208,21 +272,42 @@ Future<void> generatePDF(
|
|||||||
for (JobListing job in business.listings!) {
|
for (JobListing job in business.listings!) {
|
||||||
List<pw.Widget> jobRow = [];
|
List<pw.Widget> jobRow = [];
|
||||||
for (DataTypeJob dataType in dataTypesJob) {
|
for (DataTypeJob dataType in dataTypesJob) {
|
||||||
if (dataType != DataTypeJob.businessName) {
|
switch (dataType) {
|
||||||
var currentValue =
|
case DataTypeJob.businessName:
|
||||||
jobValueFromDataType(job, dataType);
|
|
||||||
if (currentValue != null) {
|
|
||||||
jobRow.add(pw.Padding(
|
|
||||||
child: pw.Text(currentValue),
|
|
||||||
padding: const pw.EdgeInsets.all(4.0)));
|
|
||||||
} else {
|
|
||||||
jobRow.add(pw.Container());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
jobRow.add(pw.Padding(
|
jobRow.add(pw.Padding(
|
||||||
child: pw.Text(business.name!),
|
child: pw.Text(business.name!),
|
||||||
padding: const pw.EdgeInsets.all(4.0)));
|
padding: const pw.EdgeInsets.all(4.0)));
|
||||||
|
case DataTypeJob.type:
|
||||||
|
jobRow.add(pw.Padding(
|
||||||
|
child: pw.Text(getNameFromJobType(job.type!)),
|
||||||
|
padding: const pw.EdgeInsets.all(4.0)));
|
||||||
|
case DataTypeJob.offerType:
|
||||||
|
jobRow.add(pw.Padding(
|
||||||
|
child: pw.Text(
|
||||||
|
getNameFromOfferType(job.offerType!)),
|
||||||
|
padding: const pw.EdgeInsets.all(4.0)));
|
||||||
|
default:
|
||||||
|
jobRow.add(pw.Padding(
|
||||||
|
child: pw.Text(
|
||||||
|
jobValueFromDataType(job, dataType) ??
|
||||||
|
''),
|
||||||
|
padding: const pw.EdgeInsets.all(4.0)));
|
||||||
}
|
}
|
||||||
|
// if (dataType != DataTypeJob.businessName) {
|
||||||
|
// var currentValue =
|
||||||
|
// jobValueFromDataType(job, dataType);
|
||||||
|
// if (currentValue != null) {
|
||||||
|
// jobRow.add(pw.Padding(
|
||||||
|
// child: pw.Text(currentValue),
|
||||||
|
// padding: const pw.EdgeInsets.all(4.0)));
|
||||||
|
// } else {
|
||||||
|
// jobRow.add(pw.Container());
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// jobRow.add(pw.Padding(
|
||||||
|
// child: pw.Text(business.name!),
|
||||||
|
// padding: const pw.EdgeInsets.all(4.0)));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
tableRows.add(pw.TableRow(children: jobRow));
|
tableRows.add(pw.TableRow(children: jobRow));
|
||||||
}
|
}
|
||||||
@ -344,6 +429,11 @@ Map<int, pw.TableColumnWidth> _businessColumnSizes(
|
|||||||
map.addAll(
|
map.addAll(
|
||||||
{sorted.indexOf(DataTypeBusiness.logo): const pw.FixedColumnWidth(32)});
|
{sorted.indexOf(DataTypeBusiness.logo): const pw.FixedColumnWidth(32)});
|
||||||
}
|
}
|
||||||
|
if (sorted.contains(DataTypeBusiness.type)) {
|
||||||
|
space -= 68;
|
||||||
|
map.addAll(
|
||||||
|
{sorted.indexOf(DataTypeBusiness.type): const pw.FixedColumnWidth(68)});
|
||||||
|
}
|
||||||
if (dataTypes.contains(DataTypeBusiness.contactName)) {
|
if (dataTypes.contains(DataTypeBusiness.contactName)) {
|
||||||
space -= 72;
|
space -= 72;
|
||||||
map.addAll({
|
map.addAll({
|
||||||
@ -369,7 +459,7 @@ Map<int, pw.TableColumnWidth> _businessColumnSizes(
|
|||||||
leftNum += 1;
|
leftNum += 1;
|
||||||
}
|
}
|
||||||
if (dataTypes.contains(DataTypeBusiness.notes)) {
|
if (dataTypes.contains(DataTypeBusiness.notes)) {
|
||||||
leftNum += 2;
|
leftNum += 1;
|
||||||
}
|
}
|
||||||
if (dataTypes.contains(DataTypeBusiness.description)) {
|
if (dataTypes.contains(DataTypeBusiness.description)) {
|
||||||
leftNum += 3;
|
leftNum += 3;
|
||||||
@ -391,9 +481,8 @@ Map<int, pw.TableColumnWidth> _businessColumnSizes(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (dataTypes.contains(DataTypeBusiness.notes)) {
|
if (dataTypes.contains(DataTypeBusiness.notes)) {
|
||||||
map.addAll({
|
map.addAll(
|
||||||
sorted.indexOf(DataTypeBusiness.notes): pw.FixedColumnWidth(leftNum * 2)
|
{sorted.indexOf(DataTypeBusiness.notes): pw.FixedColumnWidth(leftNum)});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (dataTypes.contains(DataTypeBusiness.description)) {
|
if (dataTypes.contains(DataTypeBusiness.description)) {
|
||||||
map.addAll({
|
map.addAll({
|
||||||
@ -416,6 +505,13 @@ Map<int, pw.TableColumnWidth> _jobColumnSizes(Set<DataTypeJob> dataTypes) {
|
|||||||
.first): const pw.FractionColumnWidth(0.2)
|
.first): const pw.FractionColumnWidth(0.2)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (dataTypes.contains(DataTypeJob.type)) {
|
||||||
|
map.addAll({
|
||||||
|
sortedDataTypes.indexOf(sortedDataTypes
|
||||||
|
.where((element) => element == DataTypeJob.type)
|
||||||
|
.first): const pw.FractionColumnWidth(0.1)
|
||||||
|
});
|
||||||
|
}
|
||||||
if (dataTypes.contains(DataTypeJob.name)) {
|
if (dataTypes.contains(DataTypeJob.name)) {
|
||||||
map.addAll({
|
map.addAll({
|
||||||
sortedDataTypes.indexOf(sortedDataTypes
|
sortedDataTypes.indexOf(sortedDataTypes
|
||||||
@ -427,7 +523,14 @@ Map<int, pw.TableColumnWidth> _jobColumnSizes(Set<DataTypeJob> dataTypes) {
|
|||||||
map.addAll({
|
map.addAll({
|
||||||
sortedDataTypes.indexOf(sortedDataTypes
|
sortedDataTypes.indexOf(sortedDataTypes
|
||||||
.where((element) => element == DataTypeJob.description)
|
.where((element) => element == DataTypeJob.description)
|
||||||
.first): const pw.FractionColumnWidth(0.4)
|
.first): const pw.FractionColumnWidth(0.3)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (dataTypes.contains(DataTypeJob.offerType)) {
|
||||||
|
map.addAll({
|
||||||
|
sortedDataTypes.indexOf(sortedDataTypes
|
||||||
|
.where((element) => element == DataTypeJob.offerType)
|
||||||
|
.first): const pw.FractionColumnWidth(0.1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (dataTypes.contains(DataTypeJob.wage)) {
|
if (dataTypes.contains(DataTypeJob.wage)) {
|
||||||
@ -456,7 +559,7 @@ dynamic businessValueFromDataType(
|
|||||||
case DataTypeBusiness.description:
|
case DataTypeBusiness.description:
|
||||||
return business.description;
|
return business.description;
|
||||||
case DataTypeBusiness.type:
|
case DataTypeBusiness.type:
|
||||||
return business.type;
|
return getNameFromBusinessType(business.type!);
|
||||||
case DataTypeBusiness.website:
|
case DataTypeBusiness.website:
|
||||||
return business.website;
|
return business.website;
|
||||||
case DataTypeBusiness.contactName:
|
case DataTypeBusiness.contactName:
|
||||||
@ -478,6 +581,10 @@ dynamic jobValueFromDataType(JobListing job, DataTypeJob dataType) {
|
|||||||
return job.name;
|
return job.name;
|
||||||
case DataTypeJob.description:
|
case DataTypeJob.description:
|
||||||
return job.description;
|
return job.description;
|
||||||
|
case DataTypeJob.type:
|
||||||
|
return job.type;
|
||||||
|
case DataTypeJob.offerType:
|
||||||
|
return job.offerType;
|
||||||
case DataTypeJob.wage:
|
case DataTypeJob.wage:
|
||||||
return job.wage;
|
return job.wage;
|
||||||
case DataTypeJob.link:
|
case DataTypeJob.link:
|
||||||
|
|||||||
@ -17,68 +17,12 @@ enum DataTypeJob {
|
|||||||
businessName,
|
businessName,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
type,
|
||||||
|
offerType,
|
||||||
wage,
|
wage,
|
||||||
link,
|
link,
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<DataTypeBusiness, int> dataTypePriorityBusiness = {
|
|
||||||
DataTypeBusiness.logo: 0,
|
|
||||||
DataTypeBusiness.name: 1,
|
|
||||||
DataTypeBusiness.description: 2,
|
|
||||||
DataTypeBusiness.type: 3,
|
|
||||||
DataTypeBusiness.website: 4,
|
|
||||||
DataTypeBusiness.contactName: 5,
|
|
||||||
DataTypeBusiness.contactEmail: 6,
|
|
||||||
DataTypeBusiness.contactPhone: 7,
|
|
||||||
DataTypeBusiness.notes: 8
|
|
||||||
};
|
|
||||||
|
|
||||||
Map<DataTypeBusiness, String> dataTypeFriendlyBusiness = {
|
|
||||||
DataTypeBusiness.logo: 'Logo',
|
|
||||||
DataTypeBusiness.name: 'Name',
|
|
||||||
DataTypeBusiness.description: 'Description',
|
|
||||||
DataTypeBusiness.type: 'Type',
|
|
||||||
DataTypeBusiness.website: 'Website',
|
|
||||||
DataTypeBusiness.contactName: 'Contact Name',
|
|
||||||
DataTypeBusiness.contactEmail: 'Contact Email',
|
|
||||||
DataTypeBusiness.contactPhone: 'Contact Phone',
|
|
||||||
DataTypeBusiness.notes: 'Notes'
|
|
||||||
};
|
|
||||||
|
|
||||||
Map<DataTypeJob, int> dataTypePriorityJob = {
|
|
||||||
DataTypeJob.businessName: 1,
|
|
||||||
DataTypeJob.name: 2,
|
|
||||||
DataTypeJob.description: 3,
|
|
||||||
DataTypeJob.wage: 4,
|
|
||||||
DataTypeJob.link: 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
Map<DataTypeJob, String> dataTypeFriendlyJob = {
|
|
||||||
DataTypeJob.businessName: 'Business Name',
|
|
||||||
DataTypeJob.name: 'Job Listing Name',
|
|
||||||
DataTypeJob.description: 'Description',
|
|
||||||
DataTypeJob.wage: 'Wage',
|
|
||||||
DataTypeJob.link: 'Additional Info Link',
|
|
||||||
};
|
|
||||||
|
|
||||||
Set<DataTypeBusiness> sortDataTypesBusiness(Set<DataTypeBusiness> set) {
|
|
||||||
List<DataTypeBusiness> list = set.toList();
|
|
||||||
list.sort((a, b) {
|
|
||||||
return dataTypePriorityBusiness[a]!.compareTo(dataTypePriorityBusiness[b]!);
|
|
||||||
});
|
|
||||||
set = list.toSet();
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<DataTypeJob> sortDataTypesJob(Set<DataTypeJob> set) {
|
|
||||||
List<DataTypeJob> list = set.toList();
|
|
||||||
list.sort((a, b) {
|
|
||||||
return dataTypePriorityJob[a]!.compareTo(dataTypePriorityJob[b]!);
|
|
||||||
});
|
|
||||||
set = list.toSet();
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum BusinessType {
|
enum BusinessType {
|
||||||
food,
|
food,
|
||||||
shop,
|
shop,
|
||||||
@ -90,6 +34,8 @@ enum BusinessType {
|
|||||||
|
|
||||||
enum JobType { cashier, server, mechanic, other }
|
enum JobType { cashier, server, mechanic, other }
|
||||||
|
|
||||||
|
enum OfferType { job, internship, apprenticeship }
|
||||||
|
|
||||||
class JobListing {
|
class JobListing {
|
||||||
int? id;
|
int? id;
|
||||||
int? businessId;
|
int? businessId;
|
||||||
@ -98,6 +44,7 @@ class JobListing {
|
|||||||
JobType? type;
|
JobType? type;
|
||||||
String? wage;
|
String? wage;
|
||||||
String? link;
|
String? link;
|
||||||
|
OfferType? offerType;
|
||||||
|
|
||||||
JobListing(
|
JobListing(
|
||||||
{this.id,
|
{this.id,
|
||||||
@ -106,7 +53,8 @@ class JobListing {
|
|||||||
required this.description,
|
required this.description,
|
||||||
this.type,
|
this.type,
|
||||||
this.wage,
|
this.wage,
|
||||||
this.link});
|
this.link,
|
||||||
|
this.offerType});
|
||||||
|
|
||||||
factory JobListing.copy(JobListing input) {
|
factory JobListing.copy(JobListing input) {
|
||||||
return JobListing(
|
return JobListing(
|
||||||
@ -117,6 +65,7 @@ class JobListing {
|
|||||||
type: input.type,
|
type: input.type,
|
||||||
wage: input.wage,
|
wage: input.wage,
|
||||||
link: input.link,
|
link: input.link,
|
||||||
|
offerType: input.offerType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +88,7 @@ class Business {
|
|||||||
{required this.id,
|
{required this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.description,
|
required this.description,
|
||||||
required this.website,
|
this.website,
|
||||||
this.type,
|
this.type,
|
||||||
this.contactName,
|
this.contactName,
|
||||||
this.contactEmail,
|
this.contactEmail,
|
||||||
@ -161,7 +110,9 @@ class Business {
|
|||||||
description: json['listings'][i]['description'],
|
description: json['listings'][i]['description'],
|
||||||
type: JobType.values.byName(json['listings'][i]['type']),
|
type: JobType.values.byName(json['listings'][i]['type']),
|
||||||
wage: json['listings'][i]['wage'],
|
wage: json['listings'][i]['wage'],
|
||||||
link: json['listings'][i]['link']));
|
link: json['listings'][i]['link'],
|
||||||
|
offerType:
|
||||||
|
OfferType.values.byName(json['listings'][i]['offerType'])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,6 +239,28 @@ String getNameFromJobType(JobType type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IconData getIconFromThemeMode(ThemeMode theme) {
|
IconData getIconFromThemeMode(ThemeMode theme) {
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
case ThemeMode.dark:
|
case ThemeMode.dark:
|
||||||
|
|||||||
@ -504,6 +504,8 @@ class BusinessSearchBar extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BusinessSearchBarState extends State<BusinessSearchBar> {
|
class _BusinessSearchBarState extends State<BusinessSearchBar> {
|
||||||
|
TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
@ -511,6 +513,7 @@ class _BusinessSearchBarState extends State<BusinessSearchBar> {
|
|||||||
height: 50,
|
height: 50,
|
||||||
child: SearchBar(
|
child: SearchBar(
|
||||||
hintText: widget.searchTextHint,
|
hintText: widget.searchTextHint,
|
||||||
|
controller: controller,
|
||||||
backgroundColor: WidgetStateProperty.resolveWith((notNeeded) {
|
backgroundColor: WidgetStateProperty.resolveWith((notNeeded) {
|
||||||
return Theme.of(context).colorScheme.surfaceContainer;
|
return Theme.of(context).colorScheme.surfaceContainer;
|
||||||
}),
|
}),
|
||||||
@ -521,7 +524,17 @@ class _BusinessSearchBarState extends State<BusinessSearchBar> {
|
|||||||
padding: EdgeInsets.only(left: 8.0),
|
padding: EdgeInsets.only(left: 8.0),
|
||||||
child: Icon(Icons.search),
|
child: Icon(Icons.search),
|
||||||
),
|
),
|
||||||
trailing: [widget.filterIconButton]),
|
trailing: [
|
||||||
|
if (controller.text != '')
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.clear),
|
||||||
|
onPressed: () {
|
||||||
|
controller.text = '';
|
||||||
|
widget.setSearchCallback('');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
widget.filterIconButton
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -624,10 +637,19 @@ class _MainSliverAppBarState extends State<MainSliverAppBar> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverAppBar(
|
return SliverAppBar(
|
||||||
title: widget.widescreen
|
title: widget.widescreen
|
||||||
? BusinessSearchBar(
|
? Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: BusinessSearchBar(
|
||||||
setSearchCallback: widget.setSearch,
|
setSearchCallback: widget.setSearch,
|
||||||
searchTextHint: widget.searchHintText,
|
searchTextHint: widget.searchHintText,
|
||||||
filterIconButton: widget.filterIconButton,
|
filterIconButton: widget.filterIconButton,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// const PreferredSize(
|
||||||
|
// preferredSize: Size(144, 0), child: SizedBox())
|
||||||
|
],
|
||||||
)
|
)
|
||||||
: const Text('Job Link'),
|
: const Text('Job Link'),
|
||||||
toolbarHeight: 70,
|
toolbarHeight: 70,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user