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.

178 lines
5.6 KiB

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