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.

112 lines
4.1 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  4. import '/views/authentication/unauthenticated_landing.dart';
  5. class ConversationsList extends StatefulWidget {
  6. const ConversationsList({Key? key}) : super(key: key);
  7. @override
  8. State<ConversationsList> createState() => _ConversationsListState();
  9. }
  10. class _ConversationsListState extends State<ConversationsList> {
  11. @override
  12. void initState() {
  13. checkLogin();
  14. super.initState();
  15. }
  16. final _suggestions = <String>[];
  17. final _biggerFont = const TextStyle(fontSize: 18);
  18. Future checkLogin() async {
  19. SharedPreferences preferences = await SharedPreferences.getInstance();
  20. print(preferences.getBool('islogin'));
  21. if (preferences.getBool('islogin') != true) {
  22. setState(() {
  23. Navigator.of(context).push(MaterialPageRoute(
  24. builder: (context) => const UnauthenticatedLandingWidget(),
  25. ));
  26. });
  27. }
  28. }
  29. Widget list() {
  30. if (_suggestions.isEmpty) {
  31. return const Center(
  32. child: Text('No Conversations'),
  33. );
  34. }
  35. return ListView.builder(
  36. itemCount: _suggestions.length,
  37. padding: const EdgeInsets.all(16.0),
  38. itemBuilder: /*1*/ (context, i) {
  39. //if (i >= _suggestions.length) {
  40. // TODO: Check for more conversations here. Remove the itemCount to use this section
  41. //_suggestions.addAll(generateWordPairs().take(10)); /*4*/
  42. //}
  43. return Column(
  44. children: [
  45. ListTile(
  46. title: Text(
  47. _suggestions[i],
  48. style: _biggerFont,
  49. ),
  50. ),
  51. const Divider(),
  52. ]
  53. );
  54. },
  55. );
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return WillPopScope(
  60. onWillPop: () async => false,
  61. child: Scaffold(
  62. appBar: AppBar(
  63. title: Text('Envelope'),
  64. actions: <Widget>[
  65. PopupMenuButton(
  66. icon: const FaIcon(FontAwesomeIcons.ellipsisVertical, color: Colors.white, size: 40),
  67. itemBuilder: (context) => [
  68. const PopupMenuItem<int>(
  69. value: 0,
  70. child: Text("Settings"),
  71. ),
  72. const PopupMenuItem<int>(
  73. value: 1,
  74. child: Text("Logout"),
  75. ),
  76. ],
  77. onSelected: (item) => selectedMenuItem(context, item),
  78. ),
  79. ],
  80. ),
  81. body: list(),
  82. ),
  83. );
  84. }
  85. void selectedMenuItem(BuildContext context, item) async {
  86. switch (item) {
  87. case 0:
  88. print("Settings");
  89. break;
  90. case 1:
  91. SharedPreferences preferences = await SharedPreferences.getInstance();
  92. preferences.setBool('islogin', false);
  93. Navigator.of(context).push(MaterialPageRoute(
  94. builder: (context) => const UnauthenticatedLandingWidget(),
  95. ));
  96. break;
  97. }
  98. }
  99. }