Skip to content

Instantly share code, notes, and snippets.

@perymerdeka
Created October 24, 2021 16:28
Show Gist options
  • Save perymerdeka/52dfe4e96c6ef8d16f2f27d194954d34 to your computer and use it in GitHub Desktop.
Save perymerdeka/52dfe4e96c6ef8d16f2f27d194954d34 to your computer and use it in GitHub Desktop.
product detail screen for my store
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:providers/providers/products.dart';
class ProductDetailScreen extends StatelessWidget {
static const routeName = '/product-detail';
const ProductDetailScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final productId =
ModalRoute.of(context)!.settings.arguments as String; // is the id!
// Provider
final product = Provider.of<ProductProvider>(context).findById(productId);
return Scaffold(
appBar: AppBar(
title: Text(product.title),
),
body: Column(
children: [
Container(
height: MediaQuery.of(context).size.height / 2,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(product.imageUrl), fit: BoxFit.cover)),
),
Center(
child: Column(
children: [
Text(product.title),
const SizedBox(
height: 10,
),
Text('\$${product.price}'),
Text(product.description)
],
),
)
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment