Compare commits

..

No commits in common. "lab3" and "master" have entirely different histories.
lab3 ... master

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
@ -7,16 +9,15 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF7BA05B)),
colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal),
useMaterial3: true,
),
home: const MyHomePage(title: 'Пучкина Анна Алексеевна!'),
home: const MyHomePage(title: 'Flutter rocks!'),
);
}
}
@ -31,7 +32,15 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
final Color _color = const Color(0xFF7BA05B);
int _counter = 0;
Color _color = Colors.teal;
void _incrementCounter() {
setState(() {
_counter++;
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
});
}
@override
Widget build(BuildContext context) {
@ -40,152 +49,30 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: _color,
title: Text(widget.title),
),
body: const MyWidget(),
);
}
}
class _CardData {
final String text;
final IconData icon;
final String descriptionText;
final String? imageUrl;
_CardData(this.text, {
this.icon = Icons.bookmark_border,
required this.descriptionText,
this.imageUrl,
});
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
'Бенто-торт "Сумерки"',
descriptionText: 'И давно тебе 17?',
imageUrl: 'https://i.pinimg.com/736x/ef/5a/80/ef5a80844de4afb19750d67f1f5be04d.jpg',
),
_CardData(
'Бенто-торт "Material Girl"',
descriptionText: 'Главное какой fabric, какой material',
imageUrl: 'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg'
),
_CardData(
'Бенто-торт "Шрек"',
descriptionText: 'Somebody once told me the world is gonna roll me',
imageUrl: 'https://i.pinimg.com/736x/a9/0d/fb/a90dfb9dfe3b4f4e1c5ce3cb99847a1e.jpg',
),
_CardData(
'Бенто-торт "Дурак"',
descriptionText: 'Сам дурак',
imageUrl: 'https://i.pinimg.com/564x/11/87/8a/11878a2f6a0c5d26e38ce68cbbe21337.jpg',
),
_CardData(
'Бенто-торт "Совунья"',
descriptionText: 'Я просто смешариков люблю',
imageUrl: 'https://i.pinimg.com/564x/85/61/d2/8561d2b601fe9eb72c4e2031bbb6ba24.jpg',
),
_CardData(
'Бенто-торт "В смысле 28?"',
descriptionText: 'Напишем любой возраст (или срок)',
imageUrl: 'https://i.pinimg.com/564x/ae/76/0a/ae760af69d9a0c12938753a372112ee4.jpg',
),
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList()),
));
}
}
class _Card extends StatelessWidget {
final String text;
final IconData icon;
final String descriptionText;
final String? imageUrl;
const _Card(this.text, {
this.icon = Icons.bookmark_border,
required this.descriptionText,
this.imageUrl,
});
factory _Card.fromData(_CardData data) =>
_Card(
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
)
]
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
width: 120,
height: 120,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
)),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: Theme
.of(context)
.textTheme
.headlineSmall,
),
Text(
descriptionText,
style: Theme
.of(context)
.textTheme
.bodyLarge,
)
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(icon),
),
],
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
if (_counter > 10)
Text(
'Че кликаем?!',
style: Theme.of(context).textTheme.headlineMedium,
)
],
),
),
);
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
backgroundColor: _color,
tooltip: 'Increment',
child: const Icon(Icons.accessible_forward_sharp),
), );
}
}