stack_wallet/lib/widgets/detail_item.dart

151 lines
4.1 KiB
Dart
Raw Normal View History

2024-01-19 23:44:01 +00:00
import 'package:flutter/material.dart';
2024-07-03 21:04:19 +00:00
import '../themes/stack_colors.dart';
import '../utilities/text_styles.dart';
import '../utilities/util.dart';
import 'conditional_parent.dart';
import 'rounded_white_container.dart';
2024-01-19 23:44:01 +00:00
class DetailItem extends StatelessWidget {
const DetailItem({
super.key,
2024-01-19 23:44:01 +00:00
required this.title,
required this.detail,
this.button,
this.overrideDetailTextColor,
2024-01-19 23:44:01 +00:00
this.showEmptyDetail = true,
this.horizontal = false,
2024-01-19 23:44:01 +00:00
this.disableSelectableText = false,
2024-07-04 15:31:41 +00:00
this.borderColor,
this.expandDetail = false,
});
2024-01-19 23:44:01 +00:00
final String title;
final String detail;
final Widget? button;
final bool showEmptyDetail;
final bool horizontal;
2024-01-19 23:44:01 +00:00
final bool disableSelectableText;
final Color? overrideDetailTextColor;
2024-07-04 15:31:41 +00:00
final Color? borderColor;
final bool expandDetail;
2024-01-19 23:44:01 +00:00
@override
Widget build(BuildContext context) {
2024-07-03 21:04:19 +00:00
TextStyle detailStyle = STextStyles.w500_14(context);
String _detail = detail;
if (overrideDetailTextColor != null) {
detailStyle = STextStyles.w500_14(context).copyWith(
color: overrideDetailTextColor,
);
}
2024-07-03 21:04:19 +00:00
if (detail.isEmpty && showEmptyDetail) {
_detail = "$title will appear here";
detailStyle = detailStyle.copyWith(
color: Theme.of(context).extension<StackColors>()!.textSubtitle3,
);
}
return DetailItemBase(
horizontal: horizontal,
2024-07-04 15:31:41 +00:00
borderColor: borderColor,
expandDetail: expandDetail,
2024-07-03 21:04:19 +00:00
title: disableSelectableText
? Text(
title,
style: STextStyles.itemSubtitle(context),
)
: SelectableText(
title,
style: STextStyles.itemSubtitle(context),
),
detail: disableSelectableText
? Text(
_detail,
style: detailStyle,
)
: SelectableText(
_detail,
style: detailStyle,
),
);
}
}
class DetailItemBase extends StatelessWidget {
const DetailItemBase({
super.key,
required this.title,
required this.detail,
this.button,
this.horizontal = false,
2024-07-04 15:31:41 +00:00
this.borderColor,
this.expandDetail = false,
2024-07-03 21:04:19 +00:00
});
final Widget title;
final Widget detail;
final Widget? button;
final bool horizontal;
2024-07-04 15:31:41 +00:00
final Color? borderColor;
final bool expandDetail;
2024-07-03 21:04:19 +00:00
@override
Widget build(BuildContext context) {
2024-01-19 23:44:01 +00:00
return ConditionalParent(
2024-07-04 15:31:41 +00:00
condition: !Util.isDesktop || borderColor != null,
2024-01-19 23:44:01 +00:00
builder: (child) => RoundedWhiteContainer(
2024-07-04 15:31:41 +00:00
padding: Util.isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
borderColor: borderColor,
2024-01-19 23:44:01 +00:00
child: child,
),
child: ConditionalParent(
2024-07-04 15:31:41 +00:00
condition: Util.isDesktop && borderColor == null,
2024-01-19 23:44:01 +00:00
builder: (child) => Padding(
padding: const EdgeInsets.all(16),
child: child,
),
child: horizontal
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2024-07-03 21:04:19 +00:00
title,
2024-07-04 15:31:41 +00:00
if (expandDetail)
const SizedBox(
width: 16,
),
ConditionalParent(
condition: expandDetail,
builder: (child) => Expanded(child: child),
child: detail,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2024-07-03 21:04:19 +00:00
title,
button ?? Container(),
],
),
const SizedBox(
height: 5,
),
2024-07-04 15:31:41 +00:00
ConditionalParent(
condition: expandDetail,
builder: (child) => Expanded(child: child),
child: detail,
),
],
),
2024-01-19 23:44:01 +00:00
),
);
}
}