bug fixes

This commit is contained in:
Muhammad Hamza 2021-10-15 11:43:13 +05:00
parent ee533bd76a
commit 6af87aa69c
2 changed files with 131 additions and 21 deletions

View File

@ -12,6 +12,7 @@ class AddContactView extends StatefulWidget {
}
class _AddContactViewState extends State<AddContactView> {
bool? _dontShow = false;
final qrKey = GlobalKey(debugLabel: 'qr');
QRViewController? _qrViewController;
Barcode? result;
@ -26,6 +27,63 @@ class _AddContactViewState extends State<AddContactView> {
}
}
// alert dialgoue
void _initialWarning() {
showDialog(
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setState) => AlertDialog(
title: const Text('Are you Sure?'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Your profile will be sent to your contact!'),
const SizedBox(height: 15.0),
Row(
children: [
Checkbox(
value: _dontShow,
onChanged: (value) {
setState(() {
_dontShow = value;
});
}),
const Text("Don't ask again")
],
),
],
),
actions: [
InkWell(
onTap: () => Navigator.pop(context),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.check, color: Colors.green),
),
),
InkWell(
onTap: () => Navigator.pop(context),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.cancel_outlined, color: Colors.red),
),
)
],
),
),
);
}
void _intiBox() {
Future.delayed(const Duration(seconds: 1), _initialWarning);
}
@override
void initState() {
_intiBox();
super.initState();
}
@override
void dispose() {
_qrViewController?.dispose();
@ -74,7 +132,16 @@ class _AddContactViewState extends State<AddContactView> {
child: Stack(
children: [
Center(
child: _qrViewBuild(),
child: GestureDetector(
onTap: () => Navigator.of(context).pop(true),
child: _qrViewBuild()),
),
const Center(
child: Text(
'Tap Here!',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
Positioned(
top: MediaQuery.of(context).size.height * 0.15,

View File

@ -71,6 +71,22 @@ class _ConversationsState extends State<Conversations> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
leadingWidth: 30,
title: InkWell(
onTap: _addNewContacts,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.bug_report,
color: Colors.grey,
size: 22.0,
),
),
),
),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Padding(
@ -78,21 +94,7 @@ class _ConversationsState extends State<Conversations> {
child: Center(
child: Column(
children: [
const SizedBox(height: 40.0),
GestureDetector(
onTap: _addNewContacts,
child: Row(
children: const [
Icon(Icons.chat, color: kPrimaryColor),
SizedBox(width: 8.0),
Text(
'Conversations',
style: kHeadingStyle,
)
],
),
),
const SizedBox(height: 5.0),
const SizedBox(height: 10.0),
_contactsList.isEmpty
? SizedBox(
height: MediaQuery.of(context).size.height * 0.7,
@ -128,12 +130,14 @@ class _ConversationsState extends State<Conversations> {
as ImageProvider
: FileImage(
// ignore: avoid_dynamic_calls
File(_conversations[index].photo)),
File(_conversations[index].photo ??
'')),
),
// ignore: avoid_dynamic_calls
title: Text(_conversations[index].name),
// ignore: avoid_dynamic_calls
subtitle: Text(_conversations[index].subtitle),
title: Text(_conversations[index].name ?? ''),
subtitle:
// ignore: avoid_dynamic_calls
Text(_conversations[index].subtitle ?? ''),
// ignore: avoid_dynamic_calls
trailing: Icon(
// ignore: avoid_dynamic_calls
@ -178,7 +182,12 @@ class _ConversationsState extends State<Conversations> {
if (value == _options[0]) {
await Navigator.pushNamed(context, AppRoutes.scanInvitation);
} else if (value == _options[1]) {
await Navigator.pushNamed(context, AppRoutes.addContact);
var value =
await Navigator.pushNamed(context, AppRoutes.addContact);
value ??= false;
if (value == true) {
_addNewMember();
}
} else {
var value = await Navigator.pushNamed(context, AppRoutes.addGroup);
if (value == true) {
@ -424,4 +433,38 @@ class _ConversationsState extends State<Conversations> {
..hideCurrentSnackBar()
..showSnackBar(snackBar);
}
void _addNewMember() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
// adding dummy contact
List<Contact> _localList = [];
final String? _local = prefs.getString('contacts');
if (_local != null) {
_localList = List.from(Contact.decode(_local));
}
List<Contact> _newList = [
Contact(
name: 'Bob',
subtitle: 'You and Bob are connected now!',
),
];
_newList = _localList + _newList;
// dummy ftn for filling the list
final String _newContacts = Contact.encode(_newList);
await prefs.setString('contacts', _newContacts);
_getContacts();
_getGroups();
const snackBar = SnackBar(
backgroundColor: Colors.green,
content: Text('New connection added!'),
);
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(snackBar);
}
}