From 61dbd23920bcf042c06bb9e7d681f48a8cf3a2b4 Mon Sep 17 00:00:00 2001 From: sofia7ya Date: Sun, 8 Dec 2024 23:43:20 +0400 Subject: [PATCH] lab 4 - 50% --- lib/main.dart | 154 +-------------------- lib/presentation/home_page/card.dart | 39 ++++++ lib/presentation/home_page/home_page.dart | 161 ++++++++++++++++++++++ 3 files changed, 201 insertions(+), 153 deletions(-) create mode 100644 lib/presentation/home_page/card.dart create mode 100644 lib/presentation/home_page/home_page.dart diff --git a/lib/main.dart b/lib/main.dart index b05e0e6..f1ff124 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_labs/presentation/home_page/home_page.dart'; void main() { runApp(const MyApp()); @@ -18,157 +19,4 @@ class MyApp extends StatelessWidget { home: const MyHomePage(title: 'Yackobchuk S.V.'), ); } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - final Color _color = Colors.orangeAccent; - - @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.ac_unit_outlined, - this.imageUrl, - }); -} - -class MyWidget extends StatelessWidget { - const MyWidget({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((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.ac_unit_outlined, - 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.only(top: 16), - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.orangeAccent, - borderRadius: BorderRadius.circular(20), - border: Border.all( - color: Colors.black12, - width: 2 - ) - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - SizedBox( - height: 140, - width: 100, - child: Image.network( - imageUrl ?? '', - errorBuilder: (_, __, ___) => const Placeholder(), - ) - ), - Expanded ( - child: Padding( - padding: const EdgeInsets.only(left: 8.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - text, - style: Theme.of(context).textTheme.headlineLarge, - ), - Text( - descriptionText, - style: Theme.of(context).textTheme.bodyLarge, - ) - ], - ), - ), - ), - const Spacer(), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: Icon(icon), - ), - ], - ), - ); - } } \ No newline at end of file diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart new file mode 100644 index 0000000..a3a5afe --- /dev/null +++ b/lib/presentation/home_page/card.dart @@ -0,0 +1,39 @@ +part of 'home_page.dart'; + +class _CardData{ + final String text; + final String descriptionText; + final IconData icon; + final String? imageUrl; + + _CardData( + this.text, { + required this.descriptionText, + this.icon= Icons.ac_unit_outlined, + this.imageUrl, + }); +} + +class _Card extends StatefulWidget { + final String text; + final String descriptionText; + final IconData icon; + final String? imageUrl; + + const _Card( + this.text, { + this.icon = Icons.ac_unit_outlined, + required this.descriptionText, + this.imageUrl, + }); + + factory _Card.fromData(_CardData data) => _Card( + data.text, + descriptionText: data.descriptionText, + icon: data.icon, + imageUrl: data.imageUrl, + ); + + @override + State<_Card> createState() => _CardState(); +} \ No newline at end of file diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart new file mode 100644 index 0000000..09f8fc8 --- /dev/null +++ b/lib/presentation/home_page/home_page.dart @@ -0,0 +1,161 @@ +import 'package:flutter/material.dart'; + +part 'card.dart'; + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + 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((e) => _Card.fromData(e)).toList(), + ) + ), + ); + } +} + +class _CardState extends State<_Card> { + bool isLiked = false; + + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.all(16), + constraints: const BoxConstraints(minHeight: 140), + decoration: BoxDecoration( + color: Colors.white70, + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(.5), + spreadRadius: 4, + offset: const Offset(0, 5), + blurRadius: 8, + ), + ], + ), + child: IntrinsicHeight( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ClipRRect( + borderRadius: const BorderRadius.only( + bottomLeft: Radius.circular(20), + topLeft: Radius.circular(20), + ), + child: SizedBox( + height: double.infinity, + width: 120, + 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.headlineLarge, + ), + Text( + widget.descriptionText, + style: Theme.of(context).textTheme.bodyLarge, + ) + ], + ), + ), + ), + Align( + alignment: Alignment.bottomRight, + child: Padding( + padding: const EdgeInsets.only( + left: 8.0, + right: 16, + bottom: 16, + ), + child: GestureDetector( + onTap: () { + setState(() { + isLiked = !isLiked; + }); + }, + child: AnimatedSwitcher( + duration: const Duration(microseconds: 200), + child: isLiked + ? const Icon( + Icons.favorite, + color: Colors.redAccent, + key: ValueKey(0), + ) + : const Icon( + Icons.favorite_border, + key: ValueKey(1), + ), + ), + ), + ), + ) + ], + ), + ), + ); + } +} \ No newline at end of file