Skip to content

Commit

Permalink
Fix product data key in API response, add url_launcher dependency, up…
Browse files Browse the repository at this point in the history
…date home page layout, and enhance checklist UI
  • Loading branch information
Polabiel committed Nov 28, 2024
1 parent f91e23c commit 79200a3
Show file tree
Hide file tree
Showing 12 changed files with 819 additions and 349 deletions.
Binary file added assets/images/Final_Diagnosis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/api/repositories/product_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ProductRepository implements IProduct {

List<ProductModels> model = [];

for (var item in response.data['products']) {
for (var item in response.data['product']) {
model.add(ProductModels.fromJson(item));
}

Expand Down
6 changes: 0 additions & 6 deletions lib/src/app/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ class HomepageState extends State<Homepage> {
),
child: const BannerComponent(hasPromotion: true),
),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: screenHeight * 0.2,
),
child: const Divider()),
Expert(),
],
),
),
Expand Down
286 changes: 204 additions & 82 deletions lib/src/app/sessions/pharmacy/pharmacy_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:gohealth/api/models/product_models.dart';
import 'package:gohealth/api/repositories/product_repository.dart';
import 'package:gohealth/src/app/sessions/pharmacy/pharmacy_controller.dart';
import 'package:gohealth/src/app/sessions/products/product_page.dart';
import 'package:url_launcher/url_launcher.dart';

class PharmacyPage extends StatefulWidget {
const PharmacyPage({super.key, required this.pharmacy});
Expand Down Expand Up @@ -34,6 +35,13 @@ class _PharmacyPageState extends State<PharmacyPage> {
}
}

void _launchMaps(String address) async {
final url = Uri.parse('https://www.google.com/maps/search/?api=1&query=${Uri.encodeFull(address)}');
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
}

@override
void initState() {
super.initState();
Expand All @@ -43,115 +51,229 @@ class _PharmacyPageState extends State<PharmacyPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.pharmacy.name!),
),
body: Padding(
padding: const EdgeInsets.all(0),
child: Column(
children: <Widget>[
Container(
height: 200,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(widget.pharmacy.image ??
"https://via.placeholder.com/150"),
fit: BoxFit.cover,
),
),
),
SizedBox(height: 16),
Text(
widget.pharmacy.name!,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 200,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: Stack(
fit: StackFit.expand,
children: [
Image.network(
widget.pharmacy.image ?? "https://via.placeholder.com/150",
fit: BoxFit.cover,
),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.7)
],
),
),
),
],
),
),
SizedBox(height: 8),
Text(
widget.pharmacy.phone!,
style: TextStyle(
fontSize: 16,
color: Colors.grey[600],
title: Text(
widget.pharmacy.name!,
style: TextStyle(color: Colors.white),
),
),
SizedBox(height: 16),
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16),
child: Text(
"Produtos disponíveis na ${widget.pharmacy.name!}",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Card(
elevation: 4,
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9,
minWidth: MediaQuery.of(context).size.width * 0.9,
),
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(Icons.phone, color: Colors.blue),
SizedBox(width: 8),
Text(
widget.pharmacy.phone!,
style: TextStyle(
color: Color(0xff1d1b20),
fontSize: 12,
fontWeight: FontWeight.w400,
letterSpacing: 0.3,
height: 1.4,
leadingDistribution:
TextLeadingDistribution.even,
),
),
],
),
SizedBox(width: 16),
Row(
children: [
Icon(Icons.location_on, color: Colors.blue),
SizedBox(width: 8),
GestureDetector(
onTap: () => _launchMaps(widget.pharmacy.geolocation!.address ?? ""),
child: Text(
(widget.pharmacy.geolocation!.address ?? "").length > 19
? "${widget.pharmacy.geolocation!.address!.substring(0, 19)}..."
: widget.pharmacy.geolocation!.address ?? "",
style: TextStyle(
color: Color(0xff1d1b20),
fontSize: 12,
fontWeight: FontWeight.w400,
letterSpacing: 0.3,
height: 1.4,
decoration: TextDecoration.underline,
leadingDistribution: TextLeadingDistribution.even,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
],
),
),
),
ListView.builder(
shrinkWrap: true,
itemCount: products.length,
itemBuilder: (context, index) {
),
SizedBox(height: 16),
TextField(
decoration: InputDecoration(
hintText: 'Buscar produtos...',
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
filled: true,
fillColor: Colors.grey[100],
),
),
],
),
),
),
products.isEmpty
? SliverFillRemaining(
child: Center(
child: CircularProgressIndicator(),
),
)
: SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.75,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
),
delegate: SliverChildBuilderDelegate(
(context, index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProductPage(
productModels: products[index],
),
builder: (context) =>
ProductPage(productModels: products[index]),
),
);
},
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
backgroundColor: Colors.primaries[Random()
.nextInt(Colors.primaries.length)],
radius: 50,
child: products[index].image != null
? ClipOval(
child: Image.network(
products[index].image!,
fit: BoxFit.cover,
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.vertical(
top: Radius.circular(12),
),
color: Colors.primaries[Random()
.nextInt(Colors.primaries.length)],
),
child: products[index].image != null
? ClipRRect(
borderRadius: BorderRadius.vertical(
top: Radius.circular(12),
),
child: Image.network(
products[index].image!,
fit: BoxFit.cover,
width: double.infinity,
),
)
: Center(
child: Icon(
Icons.medication,
size: 40,
color: Colors.white,
),
),
)
: Text(
products[index].name!,
style: const TextStyle(
color: Colors.white,
fontSize: 10,
),
),
),
),
Text(products[index].name!),
const SizedBox(height: 5),
Text(
"R\$" + products[index].price!.toString(),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
Padding(
padding: EdgeInsets.all(12),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
products[index].name!,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 8),
Text(
"R\$ ${products[index].price!.toStringAsFixed(2)}",
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
],
),
),
const SizedBox(height: 5),
],
),
),
);
},
childCount: products.length,
),
],
),
),
),
),
],
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {},
label: Text('Carrinho'),
icon: Icon(Icons.shopping_cart),
backgroundColor: Colors.blue,
),
);
}
Expand Down
Loading

0 comments on commit 79200a3

Please sign in to comment.