implemented details page
This commit is contained in:
parent
e1e9ca4194
commit
9e3be50899
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';
|
||||
|
||||
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)?;
|
||||
|
||||
class _Card extends StatefulWidget {
|
||||
@ -22,6 +8,7 @@ class _Card extends StatefulWidget {
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
final OnLikeCallback onLike;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _Card({
|
||||
super.key,
|
||||
@ -30,17 +17,20 @@ class _Card extends StatefulWidget {
|
||||
this.icon = Icons.hail,
|
||||
this.imageUrl,
|
||||
this.onLike,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
factory _Card.fromData(
|
||||
_CardData data, {
|
||||
CardData data, {
|
||||
final OnLikeCallback onLike,
|
||||
VoidCallback? onTap,
|
||||
}) => _Card(
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
onLike: onLike,
|
||||
onTap: onTap,
|
||||
);
|
||||
|
||||
@override
|
||||
@ -52,7 +42,9 @@ class _CardState extends State<_Card> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.fromLTRB(20, 8, 20, 8),
|
||||
constraints: const BoxConstraints(minHeight: 140),
|
||||
decoration: BoxDecoration(
|
||||
@ -134,6 +126,7 @@ class _CardState extends State<_Card> {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
import 'package:flutter/cupertino.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';
|
||||
|
||||
@ -42,18 +45,18 @@ class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cardsData = [
|
||||
_CardData(
|
||||
CardData(
|
||||
title: 'Title 1',
|
||||
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
|
||||
imageUrl: 'https://i.imgur.com/a9WA68S.png',
|
||||
),
|
||||
_CardData(
|
||||
CardData(
|
||||
title: 'Title 2',
|
||||
description: 'Lorem ipsum dolor sit amet',
|
||||
icon: Icons.add_chart_outlined,
|
||||
imageUrl: 'https://i.imgur.com/dAUcs6I.png',
|
||||
),
|
||||
_CardData(
|
||||
CardData(
|
||||
title: 'Title 3',
|
||||
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
|
||||
imageUrl: 'https://i.imgur.com/m2FhVAK.png',
|
||||
@ -64,7 +67,13 @@ class Body extends StatelessWidget {
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user