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.

84 lines
2.4 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import '/views/main/conversation_list.dart';
  4. import '/views/main/friend_list.dart';
  5. import '/views/main/profile.dart';
  6. import '/utils/storage/friends.dart';
  7. import '/utils/storage/conversations.dart';
  8. import '/utils/storage/messages.dart';
  9. class Home extends StatefulWidget {
  10. const Home({Key? key}) : super(key: key);
  11. @override
  12. State<Home> createState() => _HomeState();
  13. }
  14. class _HomeState extends State<Home> {
  15. @override
  16. void initState() {
  17. super.initState();
  18. updateData();
  19. }
  20. void updateData() async {
  21. await checkLogin();
  22. await updateFriends();
  23. await updateConversations();
  24. await updateMessageThreads();
  25. }
  26. // TODO: Do server GET check here
  27. Future checkLogin() async {
  28. SharedPreferences preferences = await SharedPreferences.getInstance();
  29. if (preferences.getBool('islogin') != true) {
  30. Navigator.pushNamedAndRemoveUntil(context, '/landing', ModalRoute.withName('/landing'));
  31. }
  32. }
  33. int _selectedIndex = 0;
  34. static const List<Widget> _widgetOptions = <Widget>[
  35. ConversationList(),
  36. FriendList(),
  37. Profile(),
  38. ];
  39. void _onItemTapped(int index) {
  40. setState(() {
  41. _selectedIndex = index;
  42. });
  43. }
  44. @override
  45. Widget build(BuildContext context) {
  46. return WillPopScope(
  47. onWillPop: () async => false,
  48. child: Scaffold(
  49. body: _widgetOptions.elementAt(_selectedIndex),
  50. bottomNavigationBar: BottomNavigationBar(
  51. currentIndex: _selectedIndex,
  52. onTap: _onItemTapped,
  53. selectedItemColor: Colors.red,
  54. unselectedItemColor: Colors.grey.shade600,
  55. selectedLabelStyle: const TextStyle(fontWeight: FontWeight.w600),
  56. unselectedLabelStyle: const TextStyle(fontWeight: FontWeight.w600),
  57. type: BottomNavigationBarType.fixed,
  58. items: const [
  59. BottomNavigationBarItem(
  60. icon: Icon(Icons.message),
  61. label: "Chats",
  62. ),
  63. BottomNavigationBarItem(
  64. icon: Icon(Icons.group_work),
  65. label: "Friends",
  66. ),
  67. BottomNavigationBarItem(
  68. icon: Icon(Icons.account_box),
  69. label: "Profile",
  70. ),
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. }