diff --git a/lib/presentation/shared/utils/modal_bottom_sheet_utils.dart b/lib/presentation/shared/utils/modal_bottom_sheet_utils.dart index e1bb58642..a58b4b852 100644 --- a/lib/presentation/shared/utils/modal_bottom_sheet_utils.dart +++ b/lib/presentation/shared/utils/modal_bottom_sheet_utils.dart @@ -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: diff --git a/lib/presentation/weapons/weapons_page.dart b/lib/presentation/weapons/weapons_page.dart index ea05cb960..30e1573c2 100644 --- a/lib/presentation/weapons/weapons_page.dart +++ b/lib/presentation/weapons/weapons_page.dart @@ -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 forSelection(BuildContext context, {List excludeKeys = const []}) async { + static Future forSelection( + BuildContext context, { + List excludeKeys = const [], + List weaponTypes = const [], + bool areWeaponTypesEnabled = true, + }) async { final bloc = context.read(); - bloc.add(WeaponsEvent.init(excludeKeys: excludeKeys)); + bloc.add(WeaponsEvent.init(excludeKeys: excludeKeys, weaponTypes: weaponTypes, areWeaponTypesEnabled: areWeaponTypesEnabled)); - final route = MaterialPageRoute(builder: (ctx) => const WeaponsPage(isInSelectionMode: true)); + final route = MaterialPageRoute(builder: (ctx) => WeaponsPage(isInSelectionMode: true, areWeaponTypesEnabled: areWeaponTypesEnabled)); final keyName = await Navigator.of(context).push(route); await route.completed; @@ -33,6 +40,7 @@ class WeaponsPage extends StatefulWidget { const WeaponsPage({ Key? key, this.isInSelectionMode = false, + this.areWeaponTypesEnabled = true, }) : super(key: key); @override @@ -56,7 +64,10 @@ class _WeaponsPageState extends State 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().add(WeaponsEvent.searchChanged(search: v)), ), if (state.weapons.isNotEmpty) _buildGrid(context, state.weapons) else const SliverNothingFound(), diff --git a/lib/presentation/weapons/widgets/weapon_bottom_sheet.dart b/lib/presentation/weapons/widgets/weapon_bottom_sheet.dart index 7ed2065e9..8ce78f14d 100644 --- a/lib/presentation/weapons/widgets/weapon_bottom_sheet.dart +++ b/lib/presentation/weapons/widgets/weapon_bottom_sheet.dart @@ -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 buildNavigationArgs({bool areWeaponTypesEnabled = true}) => + {_areWeaponTypesEnabledKey: areWeaponTypesEnabled}; + + static Widget getWidgetFromArgs(BuildContext context, Map args) { + assert(args.isNotEmpty); + final areWeaponTypesEnabled = args[_areWeaponTypesEnabledKey] as bool; + return WeaponBottomSheet(areWeaponTypesEnabled: areWeaponTypesEnabled); + } @override Widget build(BuildContext context) { @@ -54,6 +70,7 @@ class WeaponBottomSheet extends StatelessWidget { Text(s.type), WeaponsButtonBar( selectedValues: state.tempWeaponTypes, + enabled: areWeaponTypesEnabled, onClick: (v) => context.read().add(WeaponsEvent.weaponTypeChanged(v)), ), Text(s.rarity), @@ -68,7 +85,7 @@ class WeaponBottomSheet extends StatelessWidget { tempWeaponSubStatType: state.tempWeaponSubStatType, tempSortDirectionType: state.tempSortDirectionType, ), - const _ButtonBar(), + _ButtonBar(isResetEnabled: areWeaponTypesEnabled), ], ), ), @@ -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().add(WeaponsEvent.weaponTypeChanged(v)), ), Container(margin: Styles.endDrawerFilterItemMargin, child: Text(s.rarity)), @@ -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) { @@ -183,10 +206,12 @@ class _ButtonBar extends StatelessWidget { child: Text(s.cancel, style: TextStyle(color: theme.primaryColor)), ), OutlinedButton( - onPressed: () { - context.read().add(const WeaponsEvent.resetFilters()); - Navigator.pop(context); - }, + onPressed: !isResetEnabled + ? null + : () { + context.read().add(const WeaponsEvent.resetFilters()); + Navigator.pop(context); + }, child: Text(s.reset, style: TextStyle(color: theme.primaryColor)), ), ElevatedButton(