Загрузка данных
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(title: 'ДНС', home: HomeScreen());
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
final List<Map<String, String>> _articles = [
{
'title': 'Утюг 1',
'image': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT7ZhpyOXDshmTlwtzlxaxTOy28iGN14UTmAYA3VbO4VKcr3DzYIaMhG2I&s=10',
'copyright': 'Автор изображения: ВИДЕОСТУДИЯ КЛУБА DNS. Источник: rutube.ru',
},
{
'title': 'Утюг 2',
'image': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROcBWGmu1AlICBTAJxjOdTlSXJv6rtyKYbSkSE8kS8yg&s',
'copyright': 'Автор изображения: ВИДЕОСТУДИЯ КЛУБА DNS. Источник: rutube.ru',
},
{
'title': 'Утюг 3',
'image': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRs1PKcQt6daRCwWNoCYAs1cxSXx06pJbcPx20o5s1LmQ&s=10',
'copyright': 'Автор изображения: ВИДЕОСТУДИЯ КЛУБА DNS. Источник: rutube.ru',
},
{
'title': 'Утюг 4',
'image': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQumrC-mVpMJl7ZwpTS0MH5iSRUXzq4W7spYhTuiMZT9w&s=10',
'copyright': 'Автор изображения: ВИДЕОСТУДИЯ КЛУБА DNS. Источник: rutube.ru',
},
];
List<Widget> get _page => [
_buildHomePage(),
const Center(child: Text('Каталог')),
const Center(child: Text('Поиск')),
const Center(child: Text('Корзина')),
const Center(child: Text('Профиль')),
];
void _onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
Widget _buildHomePage() {
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemCount: _articles.length,
itemBuilder: (context, index) {
final article = _articles[index];
return Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
article['title']!,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Color(0xFF333333),
height: 1.3,
),
),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.network(
article['image']!,
width: double.infinity,
height: 300,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Container(
height: 200,
color: Colors.grey[200],
child: const Center(
child: CircularProgressIndicator(color: Colors.orange),
),
);
},
errorBuilder: (context, error, stackTrace) {
return Container(
width: double.infinity,
height: 200,
color: Colors.grey[300],
child: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.broken_image, size: 50, color: Colors.grey),
SizedBox(height: 8),
Text('Ошибка загрузки фото', style: TextStyle(color: Colors.grey)),
],
),
),
);
},
),
),
const SizedBox(height: 6),
Text(
article['copyright']!,
style: const TextStyle(fontSize: 10, color: Colors.grey),
),
],
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: const Color.fromARGB(245, 247, 250, 255),
title: const Text(
'ДНС',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.orange),
),
actions: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Row(
children: const [
Icon(Icons.location_on, color: Colors.grey, size: 18),
SizedBox(width: 4),
Text(
'Волгоград',
style: TextStyle(color: Colors.grey, fontSize: 14),
),
],
),
),
],
),
body: _page[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _currentIndex,
onTap: _onTabTapped,
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Главная"),
BottomNavigationBarItem(
icon: Icon(Icons.grid_view),
label: "Каталог",
),
BottomNavigationBarItem(icon: Icon(Icons.search), label: "Поиск"),
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart_outlined),
label: "Корзина",
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle_outlined),
label: "Профиль",
),
],
backgroundColor: const Color.fromARGB(245, 247, 250, 255),
selectedItemColor: Colors.orange,
unselectedItemColor: Colors.grey,
),
);
}
}