Overview
Today we build E-commerce Product Detail Page using Flutter
Source Code
import 'package:flutter/material.dart';
class EcommerceProductPage extends StatefulWidget {
const EcommerceProductPage({Key? key}) : super(key: key);
@override
_EcommerceProductPageState createState() => _EcommerceProductPageState();
}
class _EcommerceProductPageState extends State<EcommerceProductPage> {
List<String> availableStorages = ['8GB', '16GB', '32GB', '64GB'];
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
shadowColor: Colors.transparent,
backgroundColor: Colors.black,
title: const Text(
"Apple",
style: TextStyle(
fontSize: 25, fontWeight: FontWeight.bold, color: Colors.white),
),
centerTitle: true,
actions: const [
Icon(
Icons.favorite_border,
color: Colors.black,
size: 28,
),
SizedBox(
width: 10,
)
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(top: 10),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 2.5,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://images.unsplash.com/photo-1542393545-10f5cde2c810?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MjV8fG1hY2Jvb2t8ZW58MHx8MHx8&auto=format&fit=crop&w=500&q=60'),
),
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text(
"Macbook Pro",
style: TextStyle(
fontSize: 27,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"\$1,750.99",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white),
),
],
),
),
SizedBox(
height: 55,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: availableStorages.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () => setState(() {
_selectedIndex = index;
}),
child: storageWidget(
_selectedIndex == index, availableStorages[index]),
);
},
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 20),
child: Text(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat dolore eu fugiat nulla pariatur.",
style: TextStyle(fontSize: 16, color: Colors.grey.shade400),
),
),
),
Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 20),
height: 70,
decoration: BoxDecoration(
color: Color(0xfffD1C0F4),
borderRadius: BorderRadius.circular(50),
),
child: const Text(
"Continue",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
const SizedBox(
height: 20,
)
],
),
);
}
Widget storageWidget(isSelected, String text) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Container(
alignment: Alignment.center,
width: 75,
decoration: BoxDecoration(
color: isSelected ? Colors.black : Color(0xfffD1C0F4),
border: Border.all(color: Colors.white, width: isSelected ? 2 : 0),
borderRadius: BorderRadius.circular(40),
),
child: Text(
text,
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: isSelected ? Colors.white : Colors.black),
),
),
);
}
}