implemented details page
This commit is contained in:
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 title;
|
||||||
|
final String description;
|
||||||
|
final IconData icon;
|
||||||
|
final String? imageUrl;
|
||||||
|
|
||||||
|
CardData({
|
||||||
|
required this.title,
|
||||||
|
required this.description,
|
||||||
|
this.icon = Icons.adb,
|
||||||
|
this.imageUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
29
lib/presentation/details_page/details_page.dart
Normal file
29
lib/presentation/details_page/details_page.dart
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_android_app/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: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
|
child: Image.network(data.imageUrl ?? ''),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4),
|
||||||
|
child: Text(data.title, style: Theme.of(context).textTheme.headlineLarge),
|
||||||
|
),
|
||||||
|
Text(data.description, style: Theme.of(context).textTheme.bodyLarge),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,5 @@
|
|||||||
part of 'home_page.dart';
|
part of 'home_page.dart';
|
||||||
|
|
||||||
class _CardData {
|
|
||||||
final String title;
|
|
||||||
final String description;
|
|
||||||
final IconData icon;
|
|
||||||
final String? imageUrl;
|
|
||||||
|
|
||||||
_CardData({
|
|
||||||
required this.title,
|
|
||||||
required this.description,
|
|
||||||
this.icon = Icons.adb,
|
|
||||||
this.imageUrl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
||||||
|
|
||||||
class _Card extends StatefulWidget {
|
class _Card extends StatefulWidget {
|
||||||
@@ -22,6 +8,7 @@ class _Card extends StatefulWidget {
|
|||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallback onLike;
|
final OnLikeCallback onLike;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
const _Card({
|
const _Card({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -30,17 +17,20 @@ class _Card extends StatefulWidget {
|
|||||||
this.icon = Icons.hail,
|
this.icon = Icons.hail,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.onLike,
|
this.onLike,
|
||||||
|
this.onTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory _Card.fromData(
|
factory _Card.fromData(
|
||||||
_CardData data, {
|
CardData data, {
|
||||||
final OnLikeCallback onLike,
|
final OnLikeCallback onLike,
|
||||||
|
VoidCallback? onTap,
|
||||||
}) => _Card(
|
}) => _Card(
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
icon: data.icon,
|
icon: data.icon,
|
||||||
imageUrl: data.imageUrl,
|
imageUrl: data.imageUrl,
|
||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
|
onTap: onTap,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -52,86 +42,89 @@ class _CardState extends State<_Card> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return GestureDetector(
|
||||||
margin: const EdgeInsets.fromLTRB(20, 8, 20, 8),
|
onTap: widget.onTap,
|
||||||
constraints: const BoxConstraints(minHeight: 140),
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
margin: const EdgeInsets.fromLTRB(20, 8, 20, 8),
|
||||||
color: Colors.deepPurple.shade200,
|
constraints: const BoxConstraints(minHeight: 140),
|
||||||
borderRadius: BorderRadius.circular(15),
|
decoration: BoxDecoration(
|
||||||
boxShadow: [
|
color: Colors.deepPurple.shade200,
|
||||||
BoxShadow(
|
borderRadius: BorderRadius.circular(15),
|
||||||
color: Colors.grey.withOpacity(0.5),
|
boxShadow: [
|
||||||
spreadRadius: 4,
|
BoxShadow(
|
||||||
offset: const Offset(0, 5),
|
color: Colors.grey.withOpacity(0.5),
|
||||||
blurRadius: 6,
|
spreadRadius: 4,
|
||||||
)
|
offset: const Offset(0, 5),
|
||||||
],
|
blurRadius: 6,
|
||||||
),
|
)
|
||||||
child: IntrinsicHeight(
|
],
|
||||||
child: Row(
|
),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
child: IntrinsicHeight(
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
child: Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
ClipRRect(
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
borderRadius: const BorderRadius.only(
|
children: [
|
||||||
bottomLeft: Radius.circular(15),
|
ClipRRect(
|
||||||
topLeft: Radius.circular(15),
|
borderRadius: const BorderRadius.only(
|
||||||
),
|
bottomLeft: Radius.circular(15),
|
||||||
child: SizedBox(
|
topLeft: Radius.circular(15),
|
||||||
height: double.infinity,
|
),
|
||||||
width: 100,
|
child: SizedBox(
|
||||||
child: Image.network(
|
height: double.infinity,
|
||||||
widget.imageUrl ?? '',
|
width: 100,
|
||||||
fit: BoxFit.cover,
|
child: Image.network(
|
||||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
widget.imageUrl ?? '',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Flexible(
|
||||||
Flexible(
|
child: Padding(
|
||||||
child: Padding(
|
padding: const EdgeInsets.only(left: 12.0, top: 12, bottom: 12),
|
||||||
padding: const EdgeInsets.only(left: 12.0, top: 12, bottom: 12),
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
widget.title,
|
||||||
widget.title,
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
style: Theme.of(context).textTheme.headlineLarge,
|
),
|
||||||
),
|
Text(
|
||||||
Text(
|
widget.description,
|
||||||
widget.description,
|
style: Theme.of(context).textTheme.bodyLarge),
|
||||||
style: Theme.of(context).textTheme.bodyLarge),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Align(
|
||||||
Align(
|
alignment: Alignment.bottomRight,
|
||||||
alignment: Alignment.bottomRight,
|
child: Padding(
|
||||||
child: Padding(
|
padding: const EdgeInsets.fromLTRB(8, 0, 16, 16),
|
||||||
padding: const EdgeInsets.fromLTRB(8, 0, 16, 16),
|
child: GestureDetector(
|
||||||
child: GestureDetector(
|
onTap: () {
|
||||||
onTap: () {
|
setState(() {
|
||||||
setState(() {
|
isLiked = !isLiked;
|
||||||
isLiked = !isLiked;
|
});
|
||||||
});
|
widget.onLike?.call(widget.title, isLiked);
|
||||||
widget.onLike?.call(widget.title, isLiked);
|
},
|
||||||
},
|
child: AnimatedSwitcher(
|
||||||
child: AnimatedSwitcher(
|
duration: const Duration(milliseconds: 100),
|
||||||
duration: const Duration(milliseconds: 100),
|
child: isLiked
|
||||||
child: isLiked
|
? const Icon(
|
||||||
? const Icon(
|
Icons.favorite,
|
||||||
Icons.favorite,
|
color: Colors.redAccent,
|
||||||
color: Colors.redAccent,
|
key: ValueKey(0),
|
||||||
key: ValueKey(0),
|
)
|
||||||
)
|
: const Icon(
|
||||||
: const Icon(
|
Icons.favorite_border,
|
||||||
Icons.favorite_border,
|
key: ValueKey(1),
|
||||||
key: ValueKey(1),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_android_app/domain/models/card.dart';
|
||||||
|
import 'package:flutter_android_app/presentation/details_page/details_page.dart';
|
||||||
|
|
||||||
part 'card.dart';
|
part 'card.dart';
|
||||||
|
|
||||||
@@ -42,18 +45,18 @@ class Body extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final cardsData = [
|
final cardsData = [
|
||||||
_CardData(
|
CardData(
|
||||||
title: 'Title 1',
|
title: 'Title 1',
|
||||||
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
|
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
|
||||||
imageUrl: 'https://i.imgur.com/a9WA68S.png',
|
imageUrl: 'https://i.imgur.com/a9WA68S.png',
|
||||||
),
|
),
|
||||||
_CardData(
|
CardData(
|
||||||
title: 'Title 2',
|
title: 'Title 2',
|
||||||
description: 'Lorem ipsum dolor sit amet',
|
description: 'Lorem ipsum dolor sit amet',
|
||||||
icon: Icons.add_chart_outlined,
|
icon: Icons.add_chart_outlined,
|
||||||
imageUrl: 'https://i.imgur.com/dAUcs6I.png',
|
imageUrl: 'https://i.imgur.com/dAUcs6I.png',
|
||||||
),
|
),
|
||||||
_CardData(
|
CardData(
|
||||||
title: 'Title 3',
|
title: 'Title 3',
|
||||||
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
|
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
|
||||||
imageUrl: 'https://i.imgur.com/m2FhVAK.png',
|
imageUrl: 'https://i.imgur.com/m2FhVAK.png',
|
||||||
@@ -64,7 +67,13 @@ class Body extends StatelessWidget {
|
|||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: cardsData.map((e) => _Card.fromData(e, onLike: (title, isLiked) => _showSnackBar(context, title, isLiked))).toList(),
|
children: cardsData.map((data) {
|
||||||
|
return _Card.fromData(
|
||||||
|
data,
|
||||||
|
onLike: (String title, bool isLiked) => _showSnackBar(context, title, isLiked),
|
||||||
|
onTap: () => _navToDetails(context, data),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -82,4 +91,8 @@ class Body extends StatelessWidget {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _navToDetails(BuildContext context, CardData data) {
|
||||||
|
Navigator.push(context, CupertinoPageRoute(builder: (context) => DetailsPage(data)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user