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.

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