92 lines
2.8 KiB
Dart
92 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_labs/presentation/details_page/details_page.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_labs/domain/models/card.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.orangeAccent;
|
|
|
|
@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('mouse',
|
|
descriptionText: 'hahaha',
|
|
icon: Icons.abc,
|
|
imageUrl:
|
|
'https://sun34-1.userapi.com/impg/_DLT-op0LbBdgh5h-ILvC7IMDY5kbLR349v7vA/tX7vtk6mNlA.jpg?size=736x736&quality=96&sign=47f2b0f63bf249c62f4498fb637695d5&type=album'),
|
|
CardData('mouse2',
|
|
descriptionText: 'ahahaha',
|
|
icon: Icons.access_alarm_outlined,
|
|
imageUrl:
|
|
'https://sun165-1.userapi.com/impg/EVLbaLilqr8xw5tsqZLQQb6DSYrdKo7Q9sYSsw/H4FRwyMR6Ec.jpg?size=1280x960&quality=96&sign=f606e4ae3d1ccd27917cd1ffa6d91e58&type=album'),
|
|
CardData('mouse3',
|
|
descriptionText: 'eeee',
|
|
icon: Icons.access_alarm_rounded,
|
|
imageUrl:
|
|
'https://sun165-1.userapi.com/impg/Jxmp-zwq--f7KagZ6HuImLY7HrgQo-kyP1xhmw/JejdXP88_VE.jpg?size=736x981&quality=96&sign=5597f4d123422be17118ff4b1f570a9d&type=album'),
|
|
];
|
|
|
|
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(
|
|
'Cute hamster $title ${isLiked ? 'liked!' : 'disliked :('}',
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
backgroundColor: Colors.orangeAccent,
|
|
duration: const Duration(seconds: 1),
|
|
));
|
|
});
|
|
}
|
|
}
|