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

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '/views/authentication/unauthenticated_landing.dart';
class ConversationsList extends StatefulWidget {
const ConversationsList({Key? key}) : super(key: key);
@override
State<ConversationsList> createState() => _ConversationsListState();
}
class _ConversationsListState extends State<ConversationsList> {
@override
void initState() {
checkLogin();
super.initState();
}
final _suggestions = <String>[];
final _biggerFont = const TextStyle(fontSize: 18);
Future checkLogin() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
print(preferences.getBool('islogin'));
if (preferences.getBool('islogin') != true) {
setState(() {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const UnauthenticatedLandingWidget(),
));
});
}
}
Widget list() {
if (_suggestions.isEmpty) {
return const Center(
child: Text('No Conversations'),
);
}
return ListView.builder(
itemCount: _suggestions.length,
padding: const EdgeInsets.all(16.0),
itemBuilder: /*1*/ (context, i) {
//if (i >= _suggestions.length) {
// TODO: Check for more conversations here. Remove the itemCount to use this section
//_suggestions.addAll(generateWordPairs().take(10)); /*4*/
//}
return Column(
children: [
ListTile(
title: Text(
_suggestions[i],
style: _biggerFont,
),
),
const Divider(),
]
);
},
);
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: Scaffold(
appBar: AppBar(
title: Text('Envelope'),
actions: <Widget>[
PopupMenuButton(
icon: const FaIcon(FontAwesomeIcons.ellipsisVertical, color: Colors.white, size: 40),
itemBuilder: (context) => [
const PopupMenuItem<int>(
value: 0,
child: Text("Settings"),
),
const PopupMenuItem<int>(
value: 1,
child: Text("Logout"),
),
],
onSelected: (item) => selectedMenuItem(context, item),
),
],
),
body: list(),
),
);
}
void selectedMenuItem(BuildContext context, item) async {
switch (item) {
case 0:
print("Settings");
break;
case 1:
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setBool('islogin', false);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const UnauthenticatedLandingWidget(),
));
break;
}
}
}