Untitled
unknown
dart
2 years ago
7.0 kB
12
Indexable
import 'package:flutter/material.dart';
class MyShop extends StatefulWidget {
const MyShop({Key? key}) : super(key: key);
@override
State<MyShop> createState() => _MyShopState();
}
class _MyShopState extends State<MyShop> {
int jumlah_item = 0;
String? ukuran;
String nama_item = 'Kaos Hitam';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.orange,
centerTitle: true,
title: Text(
'My Shop',
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image/3132.jpg'),
fit: BoxFit.fill,
),
),
child: Center(
child: Column(
children: [
Image.asset(
'assets/image/item.jpg',
height: 200,
width: 200,
),
Text(
'$nama_item',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
setState(() {
jumlah_item++;
});
},
child: Text('+'),
),
SizedBox(
width: 30,
),
Text(
'$jumlah_item',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
width: 30,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: jumlah_item == 0
? null
: () {
setState(() {
jumlah_item--;
});
},
child: Text('-'),
),
],
),
Row(
children: [
Expanded(
child: RadioListTile(
title: Text('S'),
value: 'S',
groupValue: ukuran,
onChanged: (value) {
setState(() {
ukuran = value;
});
},
),
),
Expanded(
child: RadioListTile(
title: Text('M'),
value: 'M',
groupValue: ukuran,
onChanged: (value) {
setState(() {
ukuran = value;
});
},
),
),
Expanded(
child: RadioListTile(
title: Text('L'),
value: 'L',
groupValue: ukuran,
onChanged: (value) {
setState(() {
ukuran = value;
});
},
),
),
Expanded(
child: RadioListTile(
title: Text('XL'),
value: 'XL',
groupValue: ukuran,
onChanged: (value) {
setState(() {
ukuran = value;
});
},
),
),
],
),
],
),
),
),
floatingActionButton: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
),
onPressed: jumlah_item == 0 || ukuran == null
? null
: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Column(
children: [
Icon(
Icons.check_circle,
color: Colors.green,
),
Text(
'Pesanan Diterima',
style: TextStyle(
color: Colors.green,
fontSize: 20,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
),
),
],
),
content: Text(
'Pesanan anda $nama_item sebanyak $jumlah_item dengan ukuran $ukuran akan diproses'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
setState(() {
jumlah_item = 0;
ukuran = null;
});
},
child: Text(
'Oke',
style: TextStyle(
color: Colors.green,
),
),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Batal',
style: TextStyle(
color: Colors.red,
),
),
),
],
),
);
},
child: Icon(
Icons.shopping_cart,
size: 40,
),
),
);
}
}
Editor is loading...