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.

163 lines
5.0 KiB

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