Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Presentation] Added a dialog to select which items will be deleted i…
…n the inventory_page.dart
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |