глоу ап смешных хомяков
This commit is contained in:
parent
ed5e9db0ff
commit
d2cf61931e
15
lib/domain/models/card.dart
Normal file
15
lib/domain/models/card.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CardData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
CardData(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
this.icon = Icons.catching_pokemon,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
186
lib/main.dart
186
lib/main.dart
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pmu/presentation/home_page/home_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -21,190 +22,5 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final Color _color = Colors.brown.shade300;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: _color,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: const MyWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CardData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
_CardData(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
this.icon = Icons.abc,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
class MyWidget extends StatelessWidget {
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
_CardData(
|
||||
'собирается к первой паре',
|
||||
descriptionText: 'надел носочек и думает о смысле жизни',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/7d/87/eb/7d87eb75ac6fcb46beabc5cb388c7d34.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'уснул за завтраком',
|
||||
descriptionText: 'всю ночь делал лабы....а кто не делал?',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/c5/30/b6/c530b6de14c58fd8f56ec28dac9376c9.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'едет к первой паре',
|
||||
descriptionText: '(спит)',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/b2/af/d9/b2afd919443c31d2d309a1c67b11930e.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'довольный',
|
||||
descriptionText: 'пришел в столовку строилки',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/a3/12/0f/a3120feb082602247d5ab6d66bf2db61.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'делает лабы ночью',
|
||||
descriptionText: 'опять... ну ничему жизнь не учит',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://sun9-69.userapi.com/impg/MLc9nPmTUsLHA3Q53nqxz8tao0oyQ_5dGWidNQ/cXmzhWa97Qc.jpg?size=421x421&quality=95&sign=04c80f2ff2a43ff5b936190987e591e5&type=album',
|
||||
),
|
||||
_CardData(
|
||||
'всё бросил и уехал в саратов',
|
||||
descriptionText: 'я ему завидую',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/d4/25/fb/d425fb23ef181e36ad93d7c8c7f7292e.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'кушоет арбуз',
|
||||
descriptionText: 'и никакой депрессии!',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/cc/e4/38/cce4384798b795b8d69e9caa8bf02c46.jpg',
|
||||
),
|
||||
_CardData(
|
||||
'ой, а этот как сюда попал?',
|
||||
descriptionText: 'отвернитесь, он стесняется',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/64/33/86/6433869ef972b167fb43cf74e0ad40aa.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 String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
const _Card(
|
||||
this.text, {
|
||||
this.icon = Icons.abc,
|
||||
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(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white70,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(.5),
|
||||
spreadRadius: 4,
|
||||
offset: const Offset(0, 5),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: SizedBox(
|
||||
height: 310,
|
||||
width: double.infinity,
|
||||
child: Image.network(
|
||||
imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Icon(icon),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
49
lib/presentation/details_page/details_page.dart
Normal file
49
lib/presentation/details_page/details_page.dart
Normal file
@ -0,0 +1,49 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pmu/domain/models/card.dart';
|
||||
|
||||
class DetailsPage extends StatelessWidget {
|
||||
final CardData data;
|
||||
|
||||
const DetailsPage(this.data, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0), // Добавляем общий отступ слева и справа
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
child: Image.network(
|
||||
data.imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
height: 400.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4.0),
|
||||
child: Text(
|
||||
data.text,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
data.descriptionText,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontSize: 25.0,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
133
lib/presentation/home_page/card.dart
Normal file
133
lib/presentation/home_page/card.dart
Normal file
@ -0,0 +1,133 @@
|
||||
part of 'home_page.dart';
|
||||
|
||||
|
||||
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
||||
|
||||
class _Card extends StatefulWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
final OnLikeCallback onLike;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _Card(
|
||||
this.text, {
|
||||
this.icon = Icons.catching_pokemon,
|
||||
required this.descriptionText,
|
||||
this.imageUrl,
|
||||
this.onLike,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
factory _Card.fromData(
|
||||
CardData data, {
|
||||
OnLikeCallback onLike,
|
||||
VoidCallback? onTap,
|
||||
}) =>
|
||||
_Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
onLike: onLike,
|
||||
onTap: onTap,
|
||||
);
|
||||
|
||||
@override
|
||||
State<_Card> createState() => _CardState();
|
||||
}
|
||||
|
||||
class _CardState extends State<_Card> {
|
||||
bool isLiked = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
constraints: const BoxConstraints(minHeight: 140),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white70,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(.5),
|
||||
spreadRadius: 4,
|
||||
offset: const Offset(0, 5),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: IntrinsicHeight(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: SizedBox(
|
||||
height: 250,
|
||||
width: double.infinity,
|
||||
child: Image.network(
|
||||
widget.imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.text,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontSize: 25.0,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 8.0,
|
||||
right: 16.0,
|
||||
bottom: 16.0,
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
isLiked = !isLiked;
|
||||
});
|
||||
widget.onLike?.call(widget.text, isLiked);
|
||||
},
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: isLiked
|
||||
? const Icon(
|
||||
Icons.favorite,
|
||||
color: Colors.redAccent,
|
||||
key: ValueKey<int>(0),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.favorite_border,
|
||||
key: ValueKey<int>(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
138
lib/presentation/home_page/home_page.dart
Normal file
138
lib/presentation/home_page/home_page.dart
Normal file
@ -0,0 +1,138 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pmu/domain/models/card.dart';
|
||||
|
||||
import '../details_page/details_page.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> {
|
||||
final Color _color = Colors.brown.shade300;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: _color,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: const Body(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
const Body({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
CardData(
|
||||
'собирается к первой паре',
|
||||
descriptionText: 'надел носочек и думает о смысле жизни',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/7d/87/eb/7d87eb75ac6fcb46beabc5cb388c7d34.jpg',
|
||||
),
|
||||
CardData(
|
||||
'уснул за завтраком',
|
||||
descriptionText: 'всю ночь делал лабы....а кто не делал?',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/c5/30/b6/c530b6de14c58fd8f56ec28dac9376c9.jpg',
|
||||
),
|
||||
CardData(
|
||||
'едет к первой паре',
|
||||
descriptionText: '(спит)',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/b2/af/d9/b2afd919443c31d2d309a1c67b11930e.jpg',
|
||||
),
|
||||
CardData(
|
||||
'довольный',
|
||||
descriptionText: 'пришел в столовку строилки',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/a3/12/0f/a3120feb082602247d5ab6d66bf2db61.jpg',
|
||||
),
|
||||
CardData(
|
||||
'делает лабы ночью',
|
||||
descriptionText: 'опять... ну ничему жизнь не учит',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://sun9-69.userapi.com/impg/MLc9nPmTUsLHA3Q53nqxz8tao0oyQ_5dGWidNQ/cXmzhWa97Qc.jpg?size=421x421&quality=95&sign=04c80f2ff2a43ff5b936190987e591e5&type=album',
|
||||
),
|
||||
CardData(
|
||||
'всё бросил и уехал в саратов',
|
||||
descriptionText: 'я ему завидую',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/564x/d4/25/fb/d425fb23ef181e36ad93d7c8c7f7292e.jpg',
|
||||
),
|
||||
CardData(
|
||||
'кушоет арбуз',
|
||||
descriptionText: 'и никакой депрессии!',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/cc/e4/38/cce4384798b795b8d69e9caa8bf02c46.jpg',
|
||||
),
|
||||
CardData(
|
||||
'ой, а этот как сюда попал?',
|
||||
descriptionText: 'отвернитесь, он стесняется',
|
||||
icon: Icons.favorite,
|
||||
imageUrl:
|
||||
'https://i.pinimg.com/736x/64/33/86/6433869ef972b167fb43cf74e0ad40aa.jpg',
|
||||
),
|
||||
];
|
||||
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: data.map((data) {
|
||||
return _Card.fromData(
|
||||
data,
|
||||
onLike: (String title, bool isLiked) =>
|
||||
_showSnackBar(context, title, isLiked),
|
||||
onTap: () => _navToDetails(context, data),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _navToDetails(BuildContext context, CardData data){
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => DetailsPage(data)),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSnackBar(BuildContext context, String title, bool isLiked) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
'Вам ${isLiked ? 'понравился' : 'больше не нравится'} $title',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
backgroundColor: Colors.brown.shade400,
|
||||
duration: const Duration(seconds: 1),
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user