Created
October 24, 2021 16:28
-
-
Save perymerdeka/52dfe4e96c6ef8d16f2f27d194954d34 to your computer and use it in GitHub Desktop.
product detail screen for my store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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