Created
November 29, 2023 10:35
-
-
Save pixobe/4d717439acf80c6cee912dbd81ec8b79 to your computer and use it in GitHub Desktop.
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'; | |
class ProductCard extends StatefulWidget { | |
final String name; | |
final String category; | |
ProductCard({required this.name, required this.category}); | |
@override | |
_ProductCardState createState() => _ProductCardState(); | |
} | |
class _ProductCardState extends State<ProductCard> { | |
String selectedVariation = "Default"; | |
int itemCount = 1; | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
elevation: 4.0, | |
margin: EdgeInsets.all(8.0), | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
widget.name, | |
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold), | |
), | |
SizedBox(height: 8.0), | |
Text( | |
widget.category, | |
style: TextStyle(color: Colors.grey), | |
), | |
SizedBox(height: 16.0), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
// Dropdown for variations | |
DropdownButton<String>( | |
value: selectedVariation, | |
onChanged: (String? newValue) { | |
setState(() { | |
selectedVariation = newValue!; | |
}); | |
}, | |
items: <String>['Default', 'Option 1', 'Option 2', 'Option 3'] | |
.map<DropdownMenuItem<String>>((String value) { | |
return DropdownMenuItem<String>( | |
value: value, | |
child: Text(value), | |
); | |
}).toList(), | |
), | |
// Stepper for count | |
Row( | |
children: [ | |
IconButton( | |
icon: Icon(Icons.remove), | |
onPressed: () { | |
setState(() { | |
if (itemCount > 1) { | |
itemCount--; | |
} | |
}); | |
}, | |
), | |
Text(itemCount.toString()), | |
IconButton( | |
icon: Icon(Icons.add), | |
onPressed: () { | |
setState(() { | |
itemCount++; | |
}); | |
}, | |
), | |
], | |
), | |
], | |
), | |
SizedBox(height: 16.0), | |
// Add to Cart Button | |
ElevatedButton( | |
onPressed: () { | |
// Add to cart logic here | |
print('Added to cart: ${widget.name}, Variation: $selectedVariation, Count: $itemCount'); | |
}, | |
child: Text('Add to Cart'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
void main() { | |
runApp(MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: Text('Product Page')), | |
body: ProductCard(name: 'Product A', category: 'Category 1'), | |
), | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment