90 lines
2.7 KiB
Dart
90 lines
2.7 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_labs/presentation/detail_page/detail_page.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter_labs/domain/models/card.dart';
|
||
|
|
||
|
part 'card.dart';
|
||
|
|
||
|
class HomePage extends StatefulWidget {
|
||
|
const HomePage({super.key, required this.title});
|
||
|
|
||
|
final String title;
|
||
|
|
||
|
@override
|
||
|
State<HomePage> createState() => _HomePageState();
|
||
|
}
|
||
|
|
||
|
class _HomePageState extends State<HomePage> {
|
||
|
final Color _color = Colors.deepPurple;
|
||
|
|
||
|
@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('Vision',
|
||
|
descriptionText: 'Просто крутой чел',
|
||
|
icon: Icons.abc,
|
||
|
imageUrl:
|
||
|
'https://i.pinimg.com/originals/a0/18/ab/a018abf65f1f938e125d357f533f68da.png'),
|
||
|
CardData('Wolverine',
|
||
|
descriptionText: 'Менее крутой чел',
|
||
|
icon: Icons.access_alarm_outlined,
|
||
|
imageUrl:'https://i.pinimg.com/originals/1e/c7/24/1ec7240225d9cd6eecaf0c6653e3cdfc.png'
|
||
|
), CardData('Deadpool',
|
||
|
descriptionText: 'Самый крутой чел',
|
||
|
icon: Icons.access_alarm_rounded,
|
||
|
imageUrl:
|
||
|
'https://static.wikia.nocookie.net/p__/images/7/76/Deadpool_FB_Artwork_1.jpg/revision/latest/scale-to-width-down/1200?cb=20160211031703&path-prefix=protagonist'),
|
||
|
];
|
||
|
|
||
|
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(
|
||
|
'$title ${isLiked ? 'was liked!' : 'was disliked -_-'}',
|
||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||
|
),
|
||
|
backgroundColor: Colors.deepPurple,
|
||
|
duration: const Duration(seconds: 1),
|
||
|
));
|
||
|
});
|
||
|
}
|
||
|
}
|