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.

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