Skip to content

Commit

Permalink
[Presentation] Added the items_ascension_stats_dialog.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed May 21, 2022
1 parent 0906be5 commit 6b4d86f
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 20 deletions.
5 changes: 5 additions & 0 deletions lib/injection.dart
Expand Up @@ -189,6 +189,11 @@ class Injection {
return BirthdaysPerMonthBloc(genshinService, telemetryService);
}

static ItemsAscensionStatsBloc get itemsAscensionStatsBloc {
final genshinService = getIt<GenshinService>();
return ItemsAscensionStatsBloc(genshinService);
}

//TODO: USE THIS PROP
// static CalculatorAscMaterialsItemBloc get calculatorAscMaterialsItemBloc {
// final genshinService = getIt<GenshinService>();
Expand Down
40 changes: 20 additions & 20 deletions lib/presentation/charts/charts_page.dart
Expand Up @@ -16,6 +16,7 @@ import 'package:shiori/presentation/charts/widgets/birthdays_per_month_dialog.da
import 'package:shiori/presentation/charts/widgets/chart_card.dart';
import 'package:shiori/presentation/charts/widgets/chart_legend.dart';
import 'package:shiori/presentation/charts/widgets/horizontal_bar_chart.dart';
import 'package:shiori/presentation/charts/widgets/items_ascension_stats_dialog.dart';
import 'package:shiori/presentation/charts/widgets/pie_chart.dart';
import 'package:shiori/presentation/charts/widgets/vertical_bar_chart.dart';
import 'package:shiori/presentation/shared/extensions/element_type_extensions.dart';
Expand Down Expand Up @@ -212,7 +213,7 @@ class ChartsPage extends StatelessWidget {
.map(
(e) => ChartLegendIndicator(
width: min(mq.size.width / state.elements.length, 100),
color: e.getElementColorFromContext(context),
color: e.getElementColor(true),
text: s.translateElementType(e),
lineThrough: state.selectedElementTypes.contains(e),
tap: () => context.read<ChartElementsBloc>().add(ChartElementsEvent.elementSelected(type: e)),
Expand Down Expand Up @@ -290,6 +291,7 @@ class ChartsPage extends StatelessWidget {
tooltipColor: tooltipColor,
getBottomText: (value) => monthNames[value.toInt() - 1],
getLeftText: (value) => value.toInt().toString(),
rotateBottomText: true,
onBarChartTap: (index) => showDialog(
context: context,
builder: (_) => BirthdaysPerMonthDialog(month: index + 1),
Expand Down Expand Up @@ -355,25 +357,23 @@ class ChartsPage extends StatelessWidget {
),
],
),
//TODO: EMPTY
child: VerticalBarChart(
items: state.ascensionStats
.mapIndex(
(e, i) => VerticalBarDataModel(i, theme.colorScheme.primary, e.type.index, e.quantity.toDouble()),
)
.toList(),
maxY: state.maxCount + 1,
interval: (state.maxCount * 0.2).roundToDouble(),
tooltipColor: tooltipColor,
getBottomText: (value) => s.translateStatTypeWithoutValue(StatType.values[value.toInt()]),
getLeftText: (value) => value.toInt().toString(),
rotateBottomText: true,
//TODO: ON TAP
// onBarChartTap: (index) => showDialog(
// context: context,
// builder: (_) => BirthdaysPerMonthDialog(month: index + 1),
// ),
),
child: state.ascensionStats.isEmpty
? NothingFoundColumn(msg: s.nothingToShow)
: VerticalBarChart(
items: state.ascensionStats
.mapIndex((e, i) => VerticalBarDataModel(i, theme.colorScheme.primary, e.type.index, e.quantity.toDouble()))
.toList(),
maxY: state.maxCount + 1,
interval: (state.maxCount * 0.2).roundToDouble(),
tooltipColor: tooltipColor,
getBottomText: (value) => s.translateStatTypeWithoutValue(StatType.values[value.toInt()]),
getLeftText: (value) => value.toInt().toString(),
rotateBottomText: true,
onBarChartTap: (index) => showDialog(
context: context,
builder: (_) => ItemsAscensionStatsDialog(itemType: state.itemType, statType: state.ascensionStats[index].type),
),
),
),
orElse: () => const Loading(useScaffold: false),
),
Expand Down
112 changes: 112 additions & 0 deletions lib/presentation/charts/widgets/items_ascension_stats_dialog.dart
@@ -0,0 +1,112 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/domain/enums/enums.dart';
import 'package:shiori/domain/models/models.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/injection.dart';
import 'package:shiori/presentation/shared/extensions/i18n_extensions.dart';
import 'package:shiori/presentation/shared/extensions/media_query_extensions.dart';
import 'package:shiori/presentation/shared/images/circle_character.dart';
import 'package:shiori/presentation/shared/images/circle_weapon.dart';
import 'package:shiori/presentation/shared/loading.dart';
import 'package:shiori/presentation/shared/styles.dart';

class ItemsAscensionStatsDialog extends StatelessWidget {
final ItemType itemType;
final StatType statType;

const ItemsAscensionStatsDialog({
Key? key,
required this.itemType,
required this.statType,
}) : assert(itemType == ItemType.character || itemType == ItemType.weapon),
super(key: key);

@override
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
final mq = MediaQuery.of(context);
return BlocProvider<ItemsAscensionStatsBloc>(
create: (context) => Injection.itemsAscensionStatsBloc..add(ItemsAscensionStatsEvent.init(type: statType, itemType: itemType)),
child: AlertDialog(
title: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
s.translateStatTypeWithoutValue(statType),
overflow: TextOverflow.ellipsis,
),
Text(
itemType == ItemType.character ? s.characters : s.weapons,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.caption,
),
],
),
actions: [
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text(s.ok),
)
],
content: BlocBuilder<ItemsAscensionStatsBloc, ItemsAscensionStatsState>(
builder: (context, state) => state.maybeMap(
loaded: (state) => SizedBox(
height: mq.getHeightForDialogs(state.items.length + 1),
width: mq.getWidthForDialogs(),
child: ListView.builder(
itemCount: state.items.length,
itemBuilder: (context, index) => _Row(itemType: itemType, item: state.items[index]),
),
),
orElse: () => const Loading(useScaffold: false),
),
),
),
);
}
}

class _Row extends StatelessWidget {
final ItemType itemType;
final ItemCommonWithName item;

const _Row({
Key? key,
required this.itemType,
required this.item,
}) : assert(itemType == ItemType.character || itemType == ItemType.weapon),
super(key: key);

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
if (itemType == ItemType.character)
CircleCharacter(itemKey: item.key, image: item.image, radius: 40)
else
CircleWeapon(itemKey: item.key, image: item.image, radius: 40),
Expanded(
child: Padding(
padding: Styles.edgeInsetHorizontal16,
child: Text(
item.name,
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: theme.textTheme.subtitle1,
),
),
),
],
),
const Divider(),
],
);
}
}

0 comments on commit 6b4d86f

Please sign in to comment.