diff --git a/packages/simplex_app/lib/views/contacts/add_contact_view.dart b/packages/simplex_app/lib/views/contacts/add_contact_view.dart index bbc463ebf..1f3a853f6 100644 --- a/packages/simplex_app/lib/views/contacts/add_contact_view.dart +++ b/packages/simplex_app/lib/views/contacts/add_contact_view.dart @@ -12,6 +12,7 @@ class AddContactView extends StatefulWidget { } class _AddContactViewState extends State { + bool? _dontShow = false; final qrKey = GlobalKey(debugLabel: 'qr'); QRViewController? _qrViewController; Barcode? result; @@ -26,6 +27,63 @@ class _AddContactViewState extends State { } } + // 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 { 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, diff --git a/packages/simplex_app/lib/views/contacts/conversations.dart b/packages/simplex_app/lib/views/contacts/conversations.dart index 43a2be317..0455372d7 100644 --- a/packages/simplex_app/lib/views/contacts/conversations.dart +++ b/packages/simplex_app/lib/views/contacts/conversations.dart @@ -71,6 +71,22 @@ class _ConversationsState extends State { @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 { 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 { 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 { 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 { ..hideCurrentSnackBar() ..showSnackBar(snackBar); } + + void _addNewMember() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + // adding dummy contact + List _localList = []; + final String? _local = prefs.getString('contacts'); + if (_local != null) { + _localList = List.from(Contact.decode(_local)); + } + + List _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); + } }