Skip to content

Instantly share code, notes, and snippets.

@zamahaka
Created June 7, 2021 13:48
Show Gist options
  • Save zamahaka/23bb774e190a3ee883b0e0b0b153274d to your computer and use it in GitHub Desktop.
Save zamahaka/23bb774e190a3ee883b0e0b0b153274d to your computer and use it in GitHub Desktop.
Content card
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:the_house/presentation/app_icons.dart';
import 'package:the_house/presentation/core/colors.dart';
import 'package:the_house/presentation/core/constants/dimension.dart';
import 'package:the_house/presentation/core/theme/theme.dart';
import 'package:the_house/presentation/widgets/card_pattern.dart';
part 'dimensions.dart';
class ContentCard extends StatelessWidget {
final String title;
final String? subhead;
final Widget? leading;
final Widget? trailing;
final ColorCombination? colorCombination;
final VoidCallback? onPressed;
const ContentCard({
Key? key,
required this.title,
this.subhead,
this.leading,
this.trailing,
this.colorCombination,
this.onPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final colorCombination =
this.colorCombination ?? ColorCombinations.dustyRose300;
return BaseCard(
backgroundColor: colorCombination.background,
onPressed: onPressed,
child: Row(
children: [
const SizedBox(width: LIGHT_SPACE * 2),
if (leading != null) leading!,
Expanded(
child: _Body(
subhead: subhead,
colorCombination: colorCombination,
title: title,
),
),
if (trailing != null)
SizedBox(width: _TRALING_WIDTH, child: trailing),
if (trailing == null && onPressed != null) _ArrowIcon(),
],
),
);
}
}
class _Body extends StatelessWidget {
const _Body({
Key? key,
required this.subhead,
required this.colorCombination,
required this.title,
}) : super(key: key);
final String? subhead;
final ColorCombination colorCombination;
final String title;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: LIGHT_SPACE * 2),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (subhead != null) ...[
Text(
subhead!,
style: AppTheme.of(context)
.textTheme
.subhead
.copyWith(color: colorCombination.main),
),
const SizedBox(height: LIGHT_SPACE),
],
Padding(
padding: _titlePadding(),
child: Text(
title,
style: AppTheme.of(context).textTheme.h4,
),
),
],
),
);
}
EdgeInsets _titlePadding() {
return subhead == null
? const EdgeInsets.symmetric(vertical: LIGHT_SPACE)
: EdgeInsets.zero;
}
}
class _ArrowIcon extends StatelessWidget {
const _ArrowIcon({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(LIGHT_SPACE * 2),
alignment: Alignment.centerRight,
child: Icon(
AppIcons.arrow_right,
size: _ARROW_ICON_SIZE,
color: context.appTheme.primaryColorDark,
),
);
}
}
import 'package:flutter/material.dart';
import 'package:the_house/presentation/widgets/shimmer/app_shimmer.dart';
import 'content_card.dart';
class ContentCardShimmer extends StatelessWidget {
const ContentCardShimmer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AppShimmer(
child: ContentCard(subhead: 'Subhead', title: 'Title'),
);
}
}
part of 'content_card.dart';
const _TRALING_WIDTH = 120.0;
const _ARROW_ICON_SIZE = 22.0;
import 'package:flutter/material.dart';
import 'package:the_house/presentation/core/constants/dimension.dart';
import 'package:the_house/presentation/core/theme/theme.dart';
const _CIRCLE_SIZE = 48.0;
const _ICON_SIZE = 28.0;
class ContentCardIcon extends StatelessWidget {
final IconData icon;
const ContentCardIcon({
Key? key,
required this.icon,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: _CIRCLE_SIZE,
width: _CIRCLE_SIZE,
decoration: BoxDecoration(
color: context.theme.primaryColorDark,
shape: BoxShape.circle,
),
margin: const EdgeInsets.only(right: DOUBLE_LIGHT_SPACE),
child: Icon(
icon,
size: _ICON_SIZE,
color: context.theme.primaryColor.withOpacity(0.6),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/content_data/content_data.dart';
import 'package:the_house/presentation/core/colors.dart';
import 'package:the_house/presentation/core/constants/textures.dart';
import 'package:the_house/presentation/widgets/app_texture.dart';
import 'package:the_house/presentation/widgets/card_image/card_image.dart';
const _IMAGE_SMALL_SIZE = 77.0;
const _IMAGE_BIG_SIZE = 114.0;
const _IMAGE_WIDTH = 120.0;
class ContentCardImage extends StatelessWidget {
final ContentCardSize size;
final String? url;
const ContentCardImage({
Key? key,
this.url,
this.size = ContentCardSize.small,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CardImage(
url: url,
size: imageSize,
defaultImage: _DefaultImage(),
);
}
Size get imageSize {
double height;
switch (size) {
case ContentCardSize.small:
height = _IMAGE_SMALL_SIZE;
break;
case ContentCardSize.big:
height = _IMAGE_BIG_SIZE;
break;
}
return Size(_IMAGE_WIDTH, height);
}
}
class _DefaultImage extends StatelessWidget {
const _DefaultImage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AppTexture(
backgroundColor: AppColors.sage.shade300,
texture: Image.asset(
Textures.artboard5,
fit: BoxFit.cover,
color: AppColors.defaultImage,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment