Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.7 KiB

  1. import 'package:flutter/material.dart';
  2. import '/components/custom_title_bar.dart';
  3. const Map<String, String> messageExpiryValues = {
  4. 'no_expiry': 'No Expiry',
  5. 'fifteen_min': '15 Minutes',
  6. 'thirty_min': '30 Minutes',
  7. 'one_hour': '1 Hour',
  8. 'three_hour': '3 Hours',
  9. 'six_hour': '6 Hours',
  10. 'twelve_day': '12 Hours',
  11. 'one_day': '1 Day',
  12. 'three_day': '3 Days',
  13. };
  14. class SelectMessageTTL extends StatefulWidget {
  15. const SelectMessageTTL({
  16. Key? key,
  17. required this.widgetTitle,
  18. required this.backCallback,
  19. this.currentSelected,
  20. }) : super(key: key);
  21. final String widgetTitle;
  22. final Future<void> Function(String messageExpiry) backCallback;
  23. final String? currentSelected;
  24. @override
  25. _SelectMessageTTLState createState() => _SelectMessageTTLState();
  26. }
  27. class _SelectMessageTTLState extends State<SelectMessageTTL> {
  28. String selectedExpiry = 'no_expiry';
  29. @override
  30. void initState() {
  31. selectedExpiry = widget.currentSelected ?? 'no_expiry';
  32. super.initState();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. appBar: CustomTitleBar(
  38. title: Text(
  39. widget.widgetTitle,
  40. style: const TextStyle(
  41. fontSize: 28,
  42. fontWeight: FontWeight.bold
  43. )
  44. ),
  45. showBack: true,
  46. backgroundColor: Colors.transparent,
  47. beforeBack: () async {
  48. widget.backCallback(selectedExpiry);
  49. },
  50. ),
  51. body: Padding(
  52. padding: const EdgeInsets.only(top: 30),
  53. child: _list(),
  54. ),
  55. );
  56. }
  57. Widget _list() {
  58. return ListView.builder(
  59. itemCount: messageExpiryValues.length,
  60. shrinkWrap: true,
  61. itemBuilder: (context, i) {
  62. String key = messageExpiryValues.keys.elementAt(i);
  63. return GestureDetector(
  64. behavior: HitTestBehavior.opaque,
  65. onTap: () {
  66. setState(() {
  67. selectedExpiry = key;
  68. });
  69. },
  70. child: Padding(
  71. padding: const EdgeInsets.only(left: 30, right: 20, top: 8, bottom: 8),
  72. child: Row(
  73. children: [
  74. selectedExpiry == key ?
  75. const Icon(Icons.check) :
  76. const SizedBox(width: 24),
  77. const SizedBox(width: 16),
  78. Expanded(
  79. child: Align(
  80. alignment: Alignment.centerLeft,
  81. child: Text(
  82. messageExpiryValues[key] ?? '',
  83. style: const TextStyle(
  84. fontSize: 20,
  85. fontWeight: FontWeight.normal,
  86. ),
  87. ),
  88. )
  89. )
  90. ],
  91. )
  92. )
  93. );
  94. },
  95. );
  96. }
  97. }