2023-05-14 03:24:42 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'package:stackwallet/models/isar/stack_theme.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/models/notification_model.dart';
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'package:stackwallet/themes/theme_providers.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-11-14 16:40:31 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
2023-05-14 03:24:42 +00:00
|
|
|
class NotificationCard extends ConsumerWidget {
|
2022-08-26 08:11:35 +00:00
|
|
|
const NotificationCard({
|
|
|
|
Key? key,
|
|
|
|
required this.notification,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final NotificationModel notification;
|
|
|
|
|
|
|
|
String extractPrettyDateString(DateTime date) {
|
|
|
|
// TODO: format this differently to better match the design
|
|
|
|
return Format.extractDateFrom(date.millisecondsSinceEpoch ~/ 1000);
|
|
|
|
}
|
|
|
|
|
2022-11-14 16:40:31 +00:00
|
|
|
static const double mobileIconSize = 24;
|
|
|
|
static const double desktopIconSize = 30;
|
|
|
|
|
2023-05-18 18:52:48 +00:00
|
|
|
String coinIconPath(IThemeAssets assets, WidgetRef ref) {
|
2023-05-14 03:24:42 +00:00
|
|
|
try {
|
|
|
|
final coin = coinFromPrettyName(notification.coinName);
|
|
|
|
return ref.read(coinIconProvider(coin));
|
|
|
|
} catch (_) {
|
|
|
|
return notification.iconAssetName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
@override
|
2023-05-14 03:24:42 +00:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-11-14 16:40:31 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
RoundedWhiteContainer(
|
2022-11-14 16:40:31 +00:00
|
|
|
padding: isDesktop
|
|
|
|
? const EdgeInsets.symmetric(
|
|
|
|
horizontal: 20,
|
|
|
|
vertical: 10,
|
|
|
|
)
|
|
|
|
: const EdgeInsets.all(12),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
notification.changeNowId == null
|
2023-05-14 03:24:42 +00:00
|
|
|
? SvgPicture.file(
|
|
|
|
File(
|
|
|
|
coinIconPath(
|
|
|
|
ref.watch(
|
2023-05-18 18:52:48 +00:00
|
|
|
themeAssetsProvider,
|
2023-05-14 03:24:42 +00:00
|
|
|
),
|
|
|
|
ref),
|
|
|
|
),
|
2022-11-14 16:40:31 +00:00
|
|
|
width: isDesktop ? desktopIconSize : mobileIconSize,
|
|
|
|
height: isDesktop ? desktopIconSize : mobileIconSize,
|
2022-08-26 08:11:35 +00:00
|
|
|
)
|
|
|
|
: Container(
|
2022-11-14 16:40:31 +00:00
|
|
|
width: isDesktop ? desktopIconSize : mobileIconSize,
|
|
|
|
height: isDesktop ? desktopIconSize : mobileIconSize,
|
2022-08-26 08:11:35 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
borderRadius: BorderRadius.circular(24),
|
|
|
|
),
|
2023-05-14 03:24:42 +00:00
|
|
|
child: SvgPicture.file(
|
|
|
|
File(
|
|
|
|
coinIconPath(
|
|
|
|
ref.watch(
|
2023-05-18 18:52:48 +00:00
|
|
|
themeAssetsProvider,
|
2023-05-14 03:24:42 +00:00
|
|
|
),
|
|
|
|
ref),
|
|
|
|
),
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark,
|
2022-11-14 16:40:31 +00:00
|
|
|
width: isDesktop ? desktopIconSize : mobileIconSize,
|
|
|
|
height: isDesktop ? desktopIconSize : mobileIconSize,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
2022-11-14 16:40:31 +00:00
|
|
|
ConditionalParent(
|
|
|
|
condition: isDesktop && !notification.read,
|
|
|
|
builder: (child) => Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
child,
|
|
|
|
Text(
|
|
|
|
"New",
|
|
|
|
style:
|
|
|
|
STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorGreen,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
notification.title,
|
|
|
|
style: isDesktop
|
|
|
|
? STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textDark,
|
|
|
|
)
|
|
|
|
: STextStyles.titleBold12(context),
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
notification.description,
|
2022-11-14 16:40:31 +00:00
|
|
|
style: isDesktop
|
|
|
|
? STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
)
|
|
|
|
: STextStyles.label(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
extractPrettyDateString(notification.date),
|
2022-11-14 16:40:31 +00:00
|
|
|
style: isDesktop
|
|
|
|
? STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
)
|
|
|
|
: STextStyles.label(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (notification.read)
|
|
|
|
Positioned.fill(
|
|
|
|
child: RoundedContainer(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.background
|
|
|
|
.withOpacity(0.5),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|