edit_list_item.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import '../../state/app_state.dart';
  2. import 'package:flutter/material.dart';
  3. /// Item for edit page (Android).
  4. class EditListItem extends StatefulWidget {
  5. const EditListItem(this.item, this.addRemovalItem, this.removeRemovalItem,
  6. {super.key});
  7. final BaseItemType item;
  8. // Adds/removes the item from the removal list
  9. final Function addRemovalItem;
  10. final Function removeRemovalItem;
  11. @override
  12. State<StatefulWidget> createState() {
  13. return _EditListItem();
  14. }
  15. }
  16. class _EditListItem extends State<EditListItem> {
  17. // Whether item is currently selected
  18. bool? _value = false;
  19. @override
  20. Widget build(BuildContext context) {
  21. return Hero(
  22. key: widget.key,
  23. tag: widget.item.id,
  24. child: Card(
  25. child: CheckboxListTile(
  26. secondary: const Icon(Icons.drag_handle),
  27. onChanged: (e) {
  28. // Add/remove items
  29. if (e == true) {
  30. widget.addRemovalItem(widget.item.id);
  31. } else {
  32. widget.removeRemovalItem(widget.item.id);
  33. }
  34. // Set checkbox state
  35. setState(() {
  36. _value = e;
  37. });
  38. },
  39. value: _value,
  40. title: Padding(
  41. padding: const EdgeInsets.symmetric(vertical: 22, horizontal: 25),
  42. child: Column(
  43. mainAxisSize: MainAxisSize.min,
  44. // Align to start (left)
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: <Widget>[
  47. // Issuer
  48. Text(widget.item.totp.issuer,
  49. style: Theme.of(context).textTheme.titleMedium),
  50. // Generated code
  51. Padding(
  52. padding: const EdgeInsets.symmetric(vertical: 10),
  53. child: Text(widget.item.totp.placeholder,
  54. style: Theme.of(context).textTheme.displaySmall)),
  55. // Account name
  56. Text(widget.item.totp.accountName,
  57. style: Theme.of(context).textTheme.bodyMedium)
  58. ],
  59. ),
  60. ),
  61. ),
  62. ),
  63. );
  64. }
  65. }