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.

164 lines
4.7 KiB

  1. import 'package:Envelope/components/custom_title_bar.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_dotenv/flutter_dotenv.dart';
  4. import 'package:qr_flutter/qr_flutter.dart';
  5. import '/utils/storage/database.dart';
  6. import '/models/my_profile.dart';
  7. import '/components/custom_circle_avatar.dart';
  8. class Profile extends StatefulWidget {
  9. final MyProfile profile;
  10. const Profile({
  11. Key? key,
  12. required this.profile,
  13. }) : super(key: key);
  14. @override
  15. State<Profile> createState() => _ProfileState();
  16. }
  17. class _ProfileState extends State<Profile> {
  18. Widget usernameHeading() {
  19. return Row(
  20. children: <Widget> [
  21. const CustomCircleAvatar(
  22. icon: Icon(Icons.person, size: 40),
  23. imagePath: null, // TODO: Add image here
  24. radius: 30,
  25. ),
  26. const SizedBox(width: 20),
  27. Text(
  28. widget.profile.username,
  29. style: const TextStyle(
  30. fontSize: 25,
  31. fontWeight: FontWeight.w500,
  32. ),
  33. ),
  34. // widget.conversation.admin ? IconButton(
  35. // iconSize: 20,
  36. // icon: const Icon(Icons.edit),
  37. // padding: const EdgeInsets.all(5.0),
  38. // splashRadius: 25,
  39. // onPressed: () {
  40. // // TODO: Redirect to edit screen
  41. // },
  42. // ) : const SizedBox.shrink(),
  43. ],
  44. );
  45. }
  46. Widget _profileQrCode() {
  47. return Container(
  48. child: QrImage(
  49. data: 'This is a simple QR code',
  50. version: QrVersions.auto,
  51. size: 130,
  52. gapless: true,
  53. ),
  54. width: 130,
  55. height: 130,
  56. color: Theme.of(context).colorScheme.onPrimary,
  57. );
  58. }
  59. Widget settings() {
  60. return Align(
  61. alignment: Alignment.centerLeft,
  62. child: Column(
  63. crossAxisAlignment: CrossAxisAlignment.stretch,
  64. children: [
  65. const SizedBox(height: 5),
  66. TextButton.icon(
  67. label: const Text(
  68. 'Disappearing Messages',
  69. style: TextStyle(fontSize: 16)
  70. ),
  71. icon: const Icon(Icons.timer),
  72. style: ButtonStyle(
  73. alignment: Alignment.centerLeft,
  74. foregroundColor: MaterialStateProperty.resolveWith<Color>(
  75. (Set<MaterialState> states) {
  76. return Theme.of(context).colorScheme.onBackground;
  77. },
  78. )
  79. ),
  80. onPressed: () {
  81. print('Disappearing Messages');
  82. }
  83. ),
  84. ],
  85. ),
  86. );
  87. }
  88. Widget logout() {
  89. bool isTesting = dotenv.env["ENVIRONMENT"] == 'development';
  90. return Align(
  91. alignment: Alignment.centerLeft,
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.stretch,
  94. children: [
  95. TextButton.icon(
  96. label: const Text(
  97. 'Logout',
  98. style: TextStyle(fontSize: 16)
  99. ),
  100. icon: const Icon(Icons.exit_to_app),
  101. style: const ButtonStyle(
  102. alignment: Alignment.centerLeft,
  103. ),
  104. onPressed: () {
  105. deleteDb();
  106. MyProfile.logout();
  107. Navigator.pushNamedAndRemoveUntil(context, '/landing', ModalRoute.withName('/landing'));
  108. }
  109. ),
  110. isTesting ? TextButton.icon(
  111. label: const Text(
  112. 'Delete Database',
  113. style: TextStyle(fontSize: 16)
  114. ),
  115. icon: const Icon(Icons.delete_forever),
  116. style: const ButtonStyle(
  117. alignment: Alignment.centerLeft,
  118. ),
  119. onPressed: () {
  120. deleteDb();
  121. }
  122. ) : const SizedBox.shrink(),
  123. ],
  124. ),
  125. );
  126. }
  127. @override
  128. Widget build(BuildContext context) {
  129. return Scaffold(
  130. appBar: const CustomTitleBar(
  131. title: Text(
  132. 'Profile',
  133. style: TextStyle(
  134. fontSize: 32,
  135. fontWeight: FontWeight.bold
  136. )
  137. ),
  138. showBack: false,
  139. backgroundColor: Colors.transparent,
  140. ),
  141. body: Padding(
  142. padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
  143. child: Column(
  144. children: <Widget>[
  145. usernameHeading(),
  146. const SizedBox(height: 30),
  147. _profileQrCode(),
  148. const SizedBox(height: 30),
  149. settings(),
  150. const SizedBox(height: 30),
  151. logout(),
  152. ],
  153. )
  154. ),
  155. );
  156. }
  157. }