Skip to content

Commit

Permalink
[Presentation] Updated the weapons page to disable the type filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jan 19, 2022
1 parent 5d3c8d8 commit e92ec9c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/presentation/shared/utils/modal_bottom_sheet_utils.dart
Expand Up @@ -17,7 +17,8 @@ class ModalBottomSheetUtils {
case EndDrawerItemType.characters:
return const characters.CharacterBottomSheet();
case EndDrawerItemType.weapons:
return const weapons.WeaponBottomSheet();
assert(args != null);
return weapons.WeaponBottomSheet.getWidgetFromArgs(context, args!);
case EndDrawerItemType.artifacts:
return const artifacts.ArtifactBottomSheet();
case EndDrawerItemType.materials:
Expand Down
19 changes: 15 additions & 4 deletions lib/presentation/weapons/weapons_page.dart
Expand Up @@ -10,18 +10,25 @@ import 'package:shiori/presentation/shared/sliver_page_filter.dart';
import 'package:shiori/presentation/shared/sliver_scaffold_with_fab.dart';
import 'package:shiori/presentation/shared/utils/modal_bottom_sheet_utils.dart';
import 'package:shiori/presentation/shared/utils/size_utils.dart';
import 'package:shiori/presentation/weapons/widgets/weapon_bottom_sheet.dart';
import 'package:waterfall_flow/waterfall_flow.dart';

import 'widgets/weapon_card.dart';

class WeaponsPage extends StatefulWidget {
final bool isInSelectionMode;
final bool areWeaponTypesEnabled;

static Future<String?> forSelection(BuildContext context, {List<String> excludeKeys = const []}) async {
static Future<String?> forSelection(
BuildContext context, {
List<String> excludeKeys = const [],
List<WeaponType> weaponTypes = const [],
bool areWeaponTypesEnabled = true,
}) async {
final bloc = context.read<WeaponsBloc>();
bloc.add(WeaponsEvent.init(excludeKeys: excludeKeys));
bloc.add(WeaponsEvent.init(excludeKeys: excludeKeys, weaponTypes: weaponTypes, areWeaponTypesEnabled: areWeaponTypesEnabled));

final route = MaterialPageRoute<String>(builder: (ctx) => const WeaponsPage(isInSelectionMode: true));
final route = MaterialPageRoute<String>(builder: (ctx) => WeaponsPage(isInSelectionMode: true, areWeaponTypesEnabled: areWeaponTypesEnabled));
final keyName = await Navigator.of(context).push(route);
await route.completed;

Expand All @@ -33,6 +40,7 @@ class WeaponsPage extends StatefulWidget {
const WeaponsPage({
Key? key,
this.isInSelectionMode = false,
this.areWeaponTypesEnabled = true,
}) : super(key: key);

@override
Expand All @@ -56,7 +64,10 @@ class _WeaponsPageState extends State<WeaponsPage> with AutomaticKeepAliveClient
SliverPageFilter(
search: state.search,
title: s.weapons,
onPressed: () => ModalBottomSheetUtils.showAppModalBottomSheet(context, EndDrawerItemType.weapons),
onPressed: () async {
final args = WeaponBottomSheet.buildNavigationArgs(areWeaponTypesEnabled: widget.areWeaponTypesEnabled);
await ModalBottomSheetUtils.showAppModalBottomSheet(context, EndDrawerItemType.weapons, args: args);
},
searchChanged: (v) => context.read<WeaponsBloc>().add(WeaponsEvent.searchChanged(search: v)),
),
if (state.weapons.isNotEmpty) _buildGrid(context, state.weapons) else const SliverNothingFound(),
Expand Down
41 changes: 33 additions & 8 deletions lib/presentation/weapons/widgets/weapon_bottom_sheet.dart
Expand Up @@ -31,8 +31,24 @@ final _ignoredSubStats = [
StatType.healingBonusPercentage,
];

const _areWeaponTypesEnabledKey = 'areWeaponTypesEnabled';

class WeaponBottomSheet extends StatelessWidget {
const WeaponBottomSheet({Key? key}) : super(key: key);
final bool areWeaponTypesEnabled;

const WeaponBottomSheet({
Key? key,
required this.areWeaponTypesEnabled,
}) : super(key: key);

static Map<String, dynamic> buildNavigationArgs({bool areWeaponTypesEnabled = true}) =>
<String, dynamic>{_areWeaponTypesEnabledKey: areWeaponTypesEnabled};

static Widget getWidgetFromArgs(BuildContext context, Map<String, dynamic> args) {
assert(args.isNotEmpty);
final areWeaponTypesEnabled = args[_areWeaponTypesEnabledKey] as bool;
return WeaponBottomSheet(areWeaponTypesEnabled: areWeaponTypesEnabled);
}

@override
Widget build(BuildContext context) {
Expand All @@ -54,6 +70,7 @@ class WeaponBottomSheet extends StatelessWidget {
Text(s.type),
WeaponsButtonBar(
selectedValues: state.tempWeaponTypes,
enabled: areWeaponTypesEnabled,
onClick: (v) => context.read<WeaponsBloc>().add(WeaponsEvent.weaponTypeChanged(v)),
),
Text(s.rarity),
Expand All @@ -68,7 +85,7 @@ class WeaponBottomSheet extends StatelessWidget {
tempWeaponSubStatType: state.tempWeaponSubStatType,
tempSortDirectionType: state.tempSortDirectionType,
),
const _ButtonBar(),
_ButtonBar(isResetEnabled: areWeaponTypesEnabled),
],
),
),
Expand All @@ -80,12 +97,13 @@ class WeaponBottomSheet extends StatelessWidget {
builder: (ctx, state) => state.map(
loading: (_) => const Loading(useScaffold: false),
loaded: (state) => RightBottomSheet(
bottom: const _ButtonBar(),
bottom: _ButtonBar(isResetEnabled: areWeaponTypesEnabled),
children: [
Container(margin: Styles.endDrawerFilterItemMargin, child: Text(s.type)),
WeaponsButtonBar(
selectedValues: state.tempWeaponTypes,
iconSize: 40,
enabled: areWeaponTypesEnabled,
onClick: (v) => context.read<WeaponsBloc>().add(WeaponsEvent.weaponTypeChanged(v)),
),
Container(margin: Styles.endDrawerFilterItemMargin, child: Text(s.rarity)),
Expand Down Expand Up @@ -167,7 +185,12 @@ class _OtherFilters extends StatelessWidget {
}

class _ButtonBar extends StatelessWidget {
const _ButtonBar({Key? key}) : super(key: key);
final bool isResetEnabled;

const _ButtonBar({
Key? key,
required this.isResetEnabled,
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -183,10 +206,12 @@ class _ButtonBar extends StatelessWidget {
child: Text(s.cancel, style: TextStyle(color: theme.primaryColor)),
),
OutlinedButton(
onPressed: () {
context.read<WeaponsBloc>().add(const WeaponsEvent.resetFilters());
Navigator.pop(context);
},
onPressed: !isResetEnabled
? null
: () {
context.read<WeaponsBloc>().add(const WeaponsEvent.resetFilters());
Navigator.pop(context);
},
child: Text(s.reset, style: TextStyle(color: theme.primaryColor)),
),
ElevatedButton(
Expand Down

0 comments on commit e92ec9c

Please sign in to comment.