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.

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