import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(ShoppingApp());
}
class ShoppingApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Shopping App',
theme: ThemeData(
primarySwatch: Colors.blue,
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: Colors.black,
selectedItemColor: Colors.blue,
unselectedItemColor: const Color.fromARGB(255, 74, 74, 74).withOpacity(0.7),
),
),
home: ShoppingHomePage(),
);
}
}
class ShoppingHomePage extends StatefulWidget {
@override
_ShoppingHomePageState createState() => _ShoppingHomePageState();
}
class _ShoppingHomePageState extends State {
int _cartItemCount = 0;
void _addToCart() {
setState(() {
_cartItemCount++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Интернет дүкен'),
),
body: ListView.builder( // Заменяем GridView.count на ListView.builder
itemCount: 6,
itemBuilder: (context, index) {
return FutureBuilder(
future: http.get(Uri.parse('https://saybol.kz/media/products/17600/conversions/main.jpg')),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Card(
child: Column(
children: [
Image.memory(
snapshot.data!.bodyBytes,
height: 100,
width: 100,
fit: BoxFit.cover,
),
SizedBox(height: 8),
Text('Товар ${index + 1}'),
SizedBox(height: 8),
Text('Бағасы: 250 теңге'),
SizedBox(height: 8),
ElevatedButton(
onPressed: _addToCart,
child: Text('Себетке қосу'),
),
],
),
);
} else {
return Card(
child: Center(
child: CircularProgressIndicator(),
),
);
}
},
);
},
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: 2,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Басты бет',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Іздеу',
),
BottomNavigationBarItem(
icon: Stack(
children: [
Icon(Icons.shopping_cart),
Positioned(
right: 0,
child: Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
constraints: BoxConstraints(
minWidth: 13,
minHeight: 13,
),
child: Text(
'$_cartItemCount',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center,
),
),
),
],
),
label: 'Себет',
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Аккаунт',
),
],
),
);
}
}