Skip to content

Commit

Permalink
[Presentation] Added a dialog to select which items will be deleted i…
Browse files Browse the repository at this point in the history
…n the inventory_page.dart
  • Loading branch information
Wolfteam committed Jul 10, 2021
1 parent d6d575f commit b528b92
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/presentation/inventory/inventory_page.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:genshindb/generated/l10n.dart';
import 'package:genshindb/presentation/inventory/widgets/characters_inventory_tab_page.dart';
import 'package:genshindb/presentation/inventory/widgets/clear_all_dialog.dart';
import 'package:genshindb/presentation/inventory/widgets/materials_inventory_tab_page.dart';
import 'package:genshindb/presentation/inventory/widgets/weapons_inventory_tab_page.dart';
import 'package:genshindb/presentation/shared/genshin_db_icons.dart';
Expand All @@ -21,6 +22,12 @@ class InventoryPage extends StatelessWidget {
appBar: AppBar(
title: Text(s.myInventory),
bottom: TabBar(tabs: tabs),
actions: [
IconButton(
icon: const Icon(Icons.clear_all),
onPressed: () => _showClearInventoryDialog(context),
)
],
),
body: SafeArea(
child: TabBarView(
Expand All @@ -34,4 +41,8 @@ class InventoryPage extends StatelessWidget {
),
);
}

Future<void> _showClearInventoryDialog(BuildContext context) async {
await showDialog(context: context, builder: (_) => const ClearAllDialog());
}
}
75 changes: 75 additions & 0 deletions lib/presentation/inventory/widgets/clear_all_dialog.dart
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:genshindb/application/bloc.dart';
import 'package:genshindb/generated/l10n.dart';
import 'package:genshindb/presentation/shared/extensions/media_query_extensions.dart';

class ClearAllDialog extends StatefulWidget {
const ClearAllDialog({Key? key}) : super(key: key);

@override
_ClearAllDialogState createState() => _ClearAllDialogState();
}

class _ClearAllDialogState extends State<ClearAllDialog> {
String? _itemToClear;

@override
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
final items = [
s.characters,
s.weapons,
s.materials,
];
return AlertDialog(
title: Text(s.clearAll),
content: SizedBox(
width: MediaQuery.of(context).getWidthForDialogs(),
child: ListView.builder(
shrinkWrap: true,
itemCount: items.length,
itemBuilder: (ctx, index) {
final item = items.elementAt(index);
return ListTile(
key: Key('$index'),
title: Text(item, overflow: TextOverflow.ellipsis),
selectedTileColor: theme.accentColor.withOpacity(0.2),
selected: _itemToClear == item,
onTap: () {
setState(() {
_itemToClear = item;
});
},
);
},
),
),
actions: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
child: Text(s.cancel, style: TextStyle(color: theme.primaryColor)),
),
ElevatedButton(
onPressed: () => _clearAll(context),
child: Text(s.ok),
)
],
);
}

void _clearAll(BuildContext context) {
final s = S.of(context);

if (_itemToClear == s.characters) {
context.read<InventoryBloc>().add(const InventoryEvent.clearAllCharacters());
} else if (_itemToClear == s.weapons) {
context.read<InventoryBloc>().add(const InventoryEvent.clearAllWeapons());
} else if (_itemToClear == s.materials) {
context.read<InventoryBloc>().add(const InventoryEvent.clearAllMaterials());
}

Navigator.pop(context);
}
}

0 comments on commit b528b92

Please sign in to comment.