This commit is contained in:
Alenka 2024-09-25 00:25:31 +04:00
parent 46bade5080
commit 50c1b3600e
2 changed files with 63 additions and 49 deletions

BIN
assets/сайт.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,76 +1,90 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() { void main() {
runApp(const MyApp()); runApp(MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Demo', title: 'Card List',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
), ),
home: const MyHomePage(title: 'Панина Алёна Денисовна'), home: CardListScreen(),
); );
} }
} }
class MyHomePage extends StatefulWidget { class CardListScreen extends StatelessWidget {
const MyHomePage({super.key, required this.title}); final List<Map<String, String>> items = [
{
final String title; 'title': 'Москва-сити',
'description': 'ул. Пресненская Набережная, 6.',
@override 'image': 'https://avatars.mds.yandex.net/i?id=3b3ba2410de1f807162074752fa01cbf8b8f75ed-4507796-images-thumbs&n=13'
State<MyHomePage> createState() => _MyHomePageState(); },
} {
'title': 'Красная площадь',
class _MyHomePageState extends State<MyHomePage> { 'description': 'ул. Тверская, д. 10.',
int _counter = 0; 'image': 'https://avatars.mds.yandex.net/i?id=855279ca345f259516f990bd24c62645cc8eab24-4012351-images-thumbs&n=13'
},
void _incrementCounter() { {
setState(() { 'title': 'ГУМ',
'description': 'Красная площадь, 3.',
_counter++; 'image': 'https://avatars.mds.yandex.net/i?id=471812ce52e0416c0172e2ad2df2de66a7601625-13101691-images-thumbs&n=13'
}); },
} ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Куда сходить в Москве'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
), ),
body: Center( body: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, // Количество колонок
crossAxisSpacing: 10, // Расстояние между колонками
mainAxisSpacing: 10, // Расстояние между строками
),
itemCount: items.length,
itemBuilder: (context, index) {
return Card(
color: Colors.grey[300],
margin: EdgeInsets.all(10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
child: Padding(
padding: const EdgeInsets.all(8.0), // Уменьшение отступов
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, // Заставляет карточку занимать минимальный размер
mainAxisAlignment: MainAxisAlignment.center, children: [
children: <Widget>[ Expanded(
const Text( child: Image.network(
'You have pushed the button this many times:', items[index]['image']!,
fit: BoxFit.cover, // Подгоняет изображение по размеру
), ),
),
SizedBox(height: 5), // Отступ между изображением и текстом
Text( Text(
'$_counter', items[index]['title']!,
style: Theme.of(context).textTheme.headlineMedium, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), // Увеличение размера текста
),
SizedBox(height: 5), // Отступ между заголовком и описанием
Text(
items[index]['description']!,
style: TextStyle(fontSize: 14), // Увеличение размера текста
textAlign: TextAlign.center, // Центрирование текста
), ),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( );
onPressed: _incrementCounter, },
tooltip: 'Increment', ),
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
); );
} }
} }