Skip to content

Commit

Permalink
fix: alerts not rendering for non parent items
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayerOrnstein committed Dec 13, 2024
1 parent 3b9bffc commit 5d29617
Showing 1 changed file with 71 additions and 53 deletions.
124 changes: 71 additions & 53 deletions lib/worldstate/widgets/timers/alerts_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import 'package:warframestat_repository/warframestat_repository.dart';
class AlertsCard extends StatelessWidget {
const AlertsCard({super.key});

Widget _buildAlerts(Alert a, WarframestatRepository r) {
final reward =
a.mission.reward!.items.firstOrNull?.replaceAll('Blueprint', '').trim();

if (reward == null) return _AlertWidget(alert: a, isParent: false);

return BlocProvider(
create: (_) => ItemCubit(reward, r)..fetchByName(),
child: _AlertWidget(alert: a),
);
}

@override
Widget build(BuildContext context) {
final wsRepo = RepositoryProvider.of<WarframestatRepository>(context);
Expand All @@ -25,28 +37,21 @@ class AlertsCard extends StatelessWidget {
};

return Column(
children: alerts.map((a) {
final reward = a.mission.reward!.items.first
.replaceAll('Blueprint', '')
.trim();

return AppCard(
child: BlocProvider(
create: (_) => ItemCubit(reward, wsRepo)..fetchByName(),
child: _AlertWidget(alert: a),
),
);
}).toList(),
children: alerts
.map((a) => _buildAlerts(a, wsRepo))
.map((i) => AppCard(child: i))
.toList(),
);
},
);
}
}

class _AlertWidget extends StatelessWidget {
const _AlertWidget({required this.alert});
const _AlertWidget({required this.alert, this.isParent = true});

final Alert alert;
final bool isParent;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -86,15 +91,64 @@ class _AlertWidget extends StatelessWidget {
),
dense: true,
),
_AlertReward(reward: reward),
if (isParent)
_AlertItemReward(reward: reward)
else
_AlertReward(reward: reward),
],
),
);
}
}

class _AlertReward extends StatelessWidget {
const _AlertReward({required this.reward});
const _AlertReward({required this.reward, this.item});

final Reward? reward;
final Item? item;

@override
Widget build(BuildContext context) {
final credits = NumberFormat().format(reward?.credits ?? 0);

return ListTile(
leading: item != null
? CachedNetworkImage(
imageUrl: item!.imageUrl,
height: 100,
width: 60,
)
: null,
title: RichText(
text: TextSpan(
text: reward?.itemString,
style: context.theme.textTheme.titleMedium,
children: [
if (reward?.credits != null)
TextSpan(
text: ' + ${credits}cr',
style: context.textTheme.bodySmall?.copyWith(
color: context.theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
subtitle: item?.description != null
? Text(
item!.description!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
: null,
isThreeLine: item != null,
dense: true,
);
}
}

class _AlertItemReward extends StatelessWidget {
const _AlertItemReward({required this.reward});

final Reward? reward;

Expand All @@ -105,47 +159,11 @@ class _AlertReward extends StatelessWidget {
final item =
switch (state) { ItemFetchSuccess() => state.item, _ => null };

final credits = NumberFormat().format(reward?.credits ?? 0);

final child = ListTile(
leading: item != null
? CachedNetworkImage(
imageUrl: item.imageUrl,
height: 100,
width: 60,
)
: null,
title: RichText(
text: TextSpan(
text: reward?.itemString,
style: context.theme.textTheme.titleMedium,
children: [
if (reward?.credits != null)
TextSpan(
text: ' + ${credits}cr',
style: context.textTheme.bodySmall?.copyWith(
color: context.theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
subtitle: item?.description != null
? Text(
item!.description!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
: null,
isThreeLine: item != null,
dense: true,
);

if (item == null) return child;
if (item == null) return _AlertReward(reward: reward);

return EntryViewOpenContainer(
item: item as MinimalItem,
builder: (_, __) => child,
builder: (_, __) => _AlertReward(reward: reward, item: item),
);
},
);
Expand Down

0 comments on commit 5d29617

Please sign in to comment.