3 готово

This commit is contained in:
GokaPek 2024-09-24 00:30:31 +04:00
parent 69ccd3d05b
commit c406207bee
6 changed files with 174 additions and 188 deletions

View File

@ -0,0 +1,87 @@
part of 'home_page.dart';
class _CardData {
final String text;
final String info;
final String urlImage;
_CardData({required this.text, required this.info, required this.urlImage});
}
class _Card extends StatefulWidget {
final String text;
final String info;
final String urlImage;
const _Card({super.key, required this.text, required this.info, required this.urlImage});
factory _Card.fromData(_CardData data) => _Card(
text: data.text,
info: data.info,
urlImage: data.urlImage);
@override
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.network(
widget.urlImage,
fit: BoxFit.cover,
height: 150.0,
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.text,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5.0),
Text(
widget.info,
style: const TextStyle(
fontSize: 14.0,
color: Colors.grey,
),
),
Positioned(
top: 8.0,
right: 8.0,
child: GestureDetector(
onTap: () {
setState(() {
isLiked = !isLiked;
});
},
child: Icon(
Icons.favorite,
color: isLiked ? Colors.red : Colors.blueGrey,
size: 30.0,
),
),
),
],
),
),
],
),
);
}
}

View File

@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
part 'card.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const Body(),
);
}
}
class Body extends StatelessWidget {
const Body({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(text: "Батон",
info: "Белый хлеб, испечённый в виде продолговатой булки",
urlImage: "https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg"),
_CardData(text: "Багет",
info: "Длинный тонкий вид хлеба французского происхождения",
urlImage: "https://main-cdn.sbermegamarket.ru/big1/hlr-system/13/14/29/23/31/01/100027310078b0.jpg"),
_CardData(text: "Круассан",
info: "Небольшое мучное кондитерское изделие, булочка в форме полумесяца из слоёного теста",
urlImage: "https://shokoladd.ru/wp-content/uploads/2019/02/Croissant_Chocolate_Plate_Two_547531_2048x1152.jpg"),
_CardData(text: "Чиаба́тта",
info: "Итальянский пшеничный хлеб, выпекаемый с использованием закваски, дрожжей и оливкового масла",
urlImage: "https://avatars.mds.yandex.net/i?id=a9163f90a989a596b26b30ad39beaf47_l-10629685-images-thumbs&n=13")
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
)
)
);
}
}

View File

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'home_page/home_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Petrushin demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
useMaterial3: true,
),
home: const MyHomePage(title: 'Petrushin Egor Alexandrovich'),
);
}
}

View File

@ -1,168 +0,0 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'year.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Petrushin demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
useMaterial3: true,
),
home: const MyHomePage(title: 'Petrushin Egor Alexandrovich'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const GrandWidget(),
);
}
}
class GrandWidget extends StatelessWidget {
const GrandWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(text: "Батон",
info: "Белый хлеб, испечённый в виде продолговатой булки",
urlImage: "https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg"),
_CardData(text: "Багет",
info: "Длинный тонкий вид хлеба французского происхождения",
urlImage: "https://main-cdn.sbermegamarket.ru/big1/hlr-system/13/14/29/23/31/01/100027310078b0.jpg"),
_CardData(text: "Круассан",
info: "Небольшое мучное кондитерское изделие, булочка в форме полумесяца из слоёного теста",
urlImage: "https://shokoladd.ru/wp-content/uploads/2019/02/Croissant_Chocolate_Plate_Two_547531_2048x1152.jpg"),
_CardData(text: "Чиаба́тта",
info: "Итальянский пшеничный хлеб, выпекаемый с использованием закваски, дрожжей и оливкового масла",
urlImage: "https://avatars.mds.yandex.net/i?id=a9163f90a989a596b26b30ad39beaf47_l-10629685-images-thumbs&n=13")
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
)
)
);
}
}
class _CardData {
final String text;
final String info;
final String urlImage;
_CardData({required this.text, required this.info, required this.urlImage});
}
class _Card extends StatefulWidget {
final String text;
final String info;
final String urlImage;
const _Card({super.key, required this.text, required this.info, required this.urlImage});
factory _Card.fromData(_CardData data) => _Card(
text: data.text,
info: data.info,
urlImage: data.urlImage);
@override
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.network(
widget.urlImage,
fit: BoxFit.cover,
height: 150.0,
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.text,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5.0),
Text(
widget.info,
style: const TextStyle(
fontSize: 14.0,
color: Colors.grey,
),
),
Positioned(
top: 8.0,
right: 8.0,
child: GestureDetector(
onTap: () {
setState(() {
isLiked = !isLiked;
});
},
child: Icon(
Icons.favorite,
color: isLiked ? Colors.red : Colors.blueGrey,
size: 30.0,
),
),
),
],
),
),
],
),
);
}
}

View File

@ -1,19 +0,0 @@
class Year {
final String comment;
final int year;
final bool isLeap;
Year(this.comment, {required this.year}) : isLeap = _isLeapYear(year);
static bool _isLeapYear(int year) {
if (year % 4 != 0) {
return false;
} else if (year % 100 != 0) {
return true;
} else if (year % 400 != 0) {
return false;
} else {
return true;
}
}
}

View File

@ -8,7 +8,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:labs_petrushin/main.dart'; import 'package:labs_petrushin/Presentation/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {