Skip to content

Commit

Permalink
Merge pull request #28 from FEUP-LEIC-ES-2022-23/more_pages
Browse files Browse the repository at this point in the history
More pages
  • Loading branch information
francis802 authored Apr 17, 2023
2 parents f4fc5c7 + 7c0d840 commit 1d17e63
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 77 deletions.
126 changes: 85 additions & 41 deletions app/lib/screens/company_listing.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


import 'package:flutter/material.dart';
import 'package:rate_it/screens/rating_page.dart';
import 'package:rate_it/screens/reviews_page.dart';
import 'package:rate_it/screens/company_page.dart';

import '../model/company.dart';

class CompanyListing extends StatelessWidget {

final String searchResult;
CompanyListing({
super.key,
Expand All @@ -22,53 +22,97 @@ class CompanyListing extends StatelessWidget {
futureCompanies = fetchCompanies();
}
}

@override
Widget build(BuildContext context) {
initCompanies();
return FutureBuilder(
future:futureCompanies,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Company> companies = snapshot.data!;
return Center(
child: ListView(
children: [
for(var company in companies)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
future: futureCompanies,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Company> companies = snapshot.data!;

return ListView.builder(
itemCount: companies.length,
itemBuilder: (context, index) {
Company company = companies[index];
return Card(
color: Colors.blue[50],
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CompanyScreen(company: company),
),
);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EventRatingPage(company: company)),
);
},
child: Text(company.name),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ReviewsPage(company: company,),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
company.name,
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
);
},
child: Text('See Reviews'),
SizedBox(height: 8.0),
Row(
children: [
Icon(Icons.location_on),
SizedBox(width: 8.0),
Expanded(
child: Text(
company.address,
style: TextStyle(fontSize: 16.0),
),
),
],
),
SizedBox(height: 8.0),
Row(
children: [
Icon(Icons.star),
SizedBox(width: 8.0),
Text(
company.averageRating.toStringAsFixed(1),
style: TextStyle(fontSize: 16.0),
),
SizedBox(width: 8.0),
Text(
'(${company.reviews.length} reviews)',
style: TextStyle(fontSize: 16.0),
),
],
),
],
),
),
Container(
height: 200,
width: 200,
child: Image.network(company.logo),
),
],
),
SizedBox(height: 16),
],
),
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Center(child: CircularProgressIndicator());
}
},
);
),
),
);
},
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Center(child: CircularProgressIndicator());
}
},
);
}
}


136 changes: 136 additions & 0 deletions app/lib/screens/company_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:rate_it/screens/reviews_page.dart';
import '../model/company.dart';
import 'rating_page.dart';


class CompanyScreen extends StatefulWidget {
final Company company;

CompanyScreen({required this.company});

@override
_CompanyScreenState createState() => _CompanyScreenState();
}

class _CompanyScreenState extends State<CompanyScreen> {

Timer? _timer;

@override
void initState() {
_timer = Timer.periodic(Duration(milliseconds: 250), (timer) {
updateAverageRating();
});
super.initState();
}

@override
void dispose() {
_timer?.cancel();
super.dispose();
}

void updateAverageRating() {
setState(() {
widget.company.averageRating = widget.company.reviews.fold(0, (sum, review) => sum + review.rating) / widget.company.reviews.length;
if(widget.company.averageRating.isNaN) widget.company.averageRating = 0;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.company.name),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.center,
height: 100,
child: Image.network(widget.company.logo),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.company.name,
style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 16.0),
Text(
widget.company.description,
style: TextStyle(fontSize: 16.0),
),
SizedBox(height: 16.0),
Row(
children: [
Icon(Icons.location_on),
SizedBox(width: 8.0),
Text(
widget.company.address,
style: TextStyle(fontSize: 16.0),
),
],
),
SizedBox(height: 16.0),
Row(
children: [
Icon(Icons.star),
SizedBox(width: 8.0),
Text(
widget.company.averageRating.toStringAsFixed(1),
style: TextStyle(fontSize: 16.0),
),
SizedBox(width: 8.0),
Text(
'(${widget.company.reviews.length} reviews)',
style: TextStyle(fontSize: 16.0),
),
],
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EventRatingPage(company: widget.company),
),
);
},
child: Text('Rate this company'),

),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ReviewsPage(company: widget.company),
),
);
},
child: Text('Check Reviews'),
),
],

),

],
),
),
],
),
);
}
}
Loading

0 comments on commit 1d17e63

Please sign in to comment.