DiscoverModule/lib/contacts_module/ui_screen/new_contacts.dart

713 lines
27 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:discover_module/contacts_module/constants.dart';
import 'package:discover_module/contacts_module/custom_widget/text.dart';
import 'package:discover_module/contacts_module/hive_fun.dart';
import 'package:discover_module/contacts_module/provider_class/affiliationsprovider.dart';
import 'package:discover_module/contacts_module/provider_class/award_provider.dart';
import 'package:discover_module/contacts_module/provider_class/certificate_provider.dart';
import 'package:discover_module/contacts_module/provider_class/educationprovider.dart';
import 'package:discover_module/contacts_module/provider_class/email_provider.dart';
import 'package:discover_module/contacts_module/provider_class/events_provider.dart';
import 'package:discover_module/contacts_module/provider_class/hcp%20_provider.dart';
import 'package:discover_module/contacts_module/provider_class/location_provider.dart';
import 'package:discover_module/contacts_module/provider_class/nih_provider.dart';
import 'package:discover_module/contacts_module/provider_class/patent_provider.dart';
import 'package:discover_module/contacts_module/provider_class/phoneno_provider.dart';
import 'package:discover_module/contacts_module/provider_class/procedureprovider.dart';
import 'package:discover_module/contacts_module/provider_class/publications_provider.dart';
import 'package:discover_module/contacts_module/provider_class/speaker_provider.dart';
import 'package:discover_module/contacts_module/provider_class/training_provider.dart';
import 'package:discover_module/contacts_module/provider_class/trials_provider.dart';
import 'package:discover_module/contacts_module/storage_hive/kol_info/curd_kol.dart';
import 'package:discover_module/contacts_module/ui_screen/contact_filters.dart';
import 'package:discover_module/contacts_module/ui_screen/interactionform/util.dart';
import 'package:discover_module/contacts_module/ui_screen/new_new_profile.dart';
// import 'package:discover_module/constants.dart';
// import 'package:discover_module/custom_widget/text.dart';
// import 'package:discover_module/hive_fun.dart';
// import 'package:discover_module/provider_class/affiliationsprovider.dart';
// import 'package:discover_module/provider_class/award_provider.dart';
// import 'package:discover_module/provider_class/certificate_provider.dart';
// import 'package:discover_module/provider_class/educationprovider.dart';
// import 'package:discover_module/provider_class/email_provider.dart';
// import 'package:discover_module/provider_class/events_provider.dart';
// import 'package:discover_module/provider_class/hcp%20_provider.dart';
// import 'package:discover_module/provider_class/location_provider.dart';
// import 'package:discover_module/provider_class/nih_provider.dart';
// import 'package:discover_module/provider_class/patent_provider.dart';
// import 'package:discover_module/provider_class/phoneno_provider.dart';
// import 'package:discover_module/provider_class/procedureprovider.dart';
// import 'package:discover_module/provider_class/publications_provider.dart';
// import 'package:discover_module/provider_class/speaker_provider.dart';
// import 'package:discover_module/provider_class/training_provider.dart';
// import 'package:discover_module/provider_class/trials_provider.dart';
// import 'package:discover_module/storage_hive/kol_info/curd_kol.dart';
// import 'package:discover_module/ui_screen/contact_filters.dart';
// import 'package:discover_module/ui_screen/interactionform/util.dart';
// import 'package:discover_module/ui_screen/new_new_profile.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'package:flutter_profile_picture/flutter_profile_picture.dart';
final ValueNotifier<List<String>> ddlist = ValueNotifier<List<String>>([]);
String selectedValue = '';
String? selectedType;
final TextEditingController searchController = TextEditingController();
TextEditingController textEditingController = TextEditingController();
class Contacts1 extends StatefulWidget {
const Contacts1({Key? key}) : super(key: key);
@override
State<Contacts1> createState() => _Contacts1State();
}
class _Contacts1State extends State<Contacts1> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
bool _switchValue = false;
bool isOnline2 = true;
bool isSearchClickd = false;
List displayedHCPList = [];
List myContactHCPList = [];
final List<String> _selectedIndices = [];
final List<int> _selectedremoveIndices = [];
bool longpress = false;
bool longpressmy = false;
late List<dynamic> hcpdataList;
// ignore: prefer_typing_uninitialized_variables
var hcpDataProvider1;
List<ConnectivityResult> _connectionStatus = [ConnectivityResult.none];
final Connectivity _connectivity = Connectivity();
late StreamSubscription<List<ConnectivityResult>> _connectivitySubscription;
get developer => null;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
initConnectivity();
_connectivitySubscription =
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
hcpList();
});
}
Future<void> hcpList() async {
hcpDataProvider1 = Provider.of<hcpProvider>(context, listen: false);
await hcpDataProvider1.getHCPProvider();
final hcplist = hcpDataProvider1.list;
hcpdataList = hcplist;
}
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Color.fromARGB(255, 0, 71, 132)));
return SafeArea(
child: Scaffold(
key: _scaffoldKey, // Assign the key to the Scaffold
appBar: AppBar(
automaticallyImplyLeading: false,
title: isSearchClickd
? Container(
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5.0)),
child: TextField(
controller: searchController,
onChanged: (value) {
setState(() {});
},
decoration: InputDecoration(
fillColor: Constants.k2color,
contentPadding: EdgeInsets.symmetric(vertical: 9.0),
border: OutlineInputBorder(),
hintText: "Search",
// labelText: ' Search',
prefixIcon: Icon(
Icons.search,
),
),
),
)
: Text1(title: "Contacts"),
actions: [
IconButton(
onPressed: () {
setState(() {
isSearchClickd = !isSearchClickd;
if (!isSearchClickd) {
searchController.clear();
}
});
},
icon: Icon(isSearchClickd ? Icons.close : Icons.search))
],
),
endDrawer: FilterDrawer(_switchValue, searchController),
// Drawer(
// child: listdata(),
// ),
body: Consumer<hcpProvider>(
builder: (context, hcpProvider, child) {
print("_selectedValueConsumerConsumer_isss: $selectedValue");
if (selectedValue.isNotEmpty) {
searchController.text = selectedValue;
} else {
searchController.text = "";
}
!_switchValue
? displayedHCPList =
hcpProvider.searchHCP(searchController.text)
: myContactHCPList =
HiveFunctions.getindexUser(searchController.text);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Wrap(
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 2.0),
child: CupertinoSwitch(
activeColor: Color.fromARGB(255, 0, 71, 132),
value: _switchValue,
onChanged: (value) {
setState(() {
_switchValue = value;
});
},
),
),
Padding(
padding:
const EdgeInsets.only(right: 8.0, top: 9.0),
child: !_switchValue
? Text1(
title: 'My Contacts',
txtfont: 15,
txtcolor: Colors.grey,
)
: Text1(
title: 'My Contacts',
txtfont: 15,
txtcolor: Colors.grey,
))
],
),
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Row(
children: [
GestureDetector(
onTap: () {
print("SearchVon: ${searchController.text}");
setState(() {
selectedValue = '';
});
},
child: Text1(title: 'My Filters'),
// child: Text1(
// title: _connectionStatus[0].toString(),
// )
),
IconButton(
onPressed: () async {
_scaffoldKey.currentState?.openEndDrawer();
},
icon: const Icon(
Icons.sort,
size: 30,
)),
],
),
)
],
),
const SizedBox(
height: 5,
),
// !_switchValue
// ? hcpContactlistview(displayedHCPList)
// : hcpContactlistview(myContactHCPList),
// contactsBottomdailog()
!_switchValue
? _connectionStatus[0]
.toString()
.contains("ConnectivityResult.none")
? hcpContactlistview(myContactHCPList)
: hcpContactlistview(displayedHCPList)
: hcpContactlistview(myContactHCPList),
contactsBottomdailog()
],
);
},
),
),
);
}
Future<void> _showMyDialog(String data) async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Successfully'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
// Text('This is a demo alert dialog.'),
Text(data),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
setState(() {
_selectedIndices.clear();
_selectedremoveIndices.clear();
longpress = false;
longpressmy = false;
});
},
),
],
);
},
);
}
Map<String, dynamic> findRecordById(
List displayedHCPList, String selectedIndic) {
// print(
// "Gettt11111 ${displayedHCPList.firstWhere((element) => element['id'] == int.parse(selectedIndic))}");
return displayedHCPList
.firstWhere((element) => element['id'] == int.parse(selectedIndic));
}
hcpContactlistview(List HCPList) {
return Expanded(
child: ListView.builder(
itemCount: HCPList.length,
itemBuilder: (BuildContext context, int index) {
var data = HCPList[index];
print("CheckinggggImage_path: ${data['img_path']}");
return Column(
children: [
ListTile(
onLongPress: () {
print("LongPresss");
setState(() {
longpress = true;
});
},
onTap: () async {
print("Check_data11 = ${data}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewProfile1(text: data),
),
);
},
leading: data["img_path"] == ""
? ProfilePicture(
name: data["First Name"],
radius: 30,
fontsize: 12,
)
: ClipOval(
child: SizedBox.fromSize(
size: const Size.fromRadius(30),
child: CachedNetworkImage(
imageUrl: data["img_path"],
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.fill,
),
),
),
),
),
),
trailing: Visibility(
visible: longpress,
child: !_switchValue
? Checkbox(
value:
_selectedIndices.contains(data["id"].toString()),
onChanged: (value) {
setState(() {
if (value!) {
print("Datata_issss_iddd: ${data["id"]}");
_selectedIndices.add(data["id"].toString());
} else {
_selectedIndices.remove(data["id"].toString());
}
print("id_total123: ${_selectedIndices}");
});
})
: Checkbox(
value: _selectedremoveIndices.contains(data["id"]),
onChanged: (value) {
setState(() {
if (value!) {
_selectedremoveIndices.add(data["id"]);
} else {
_selectedremoveIndices.remove(data["id"]);
}
print("id_total: ${_selectedremoveIndices}");
});
}),
),
title: Text1(
title: data['name'],
fontweight: FontWeight.bold,
txtfont: isTablet ? 22 : 16,
),
subtitle: Column(
children: [
Row(
children: [
Expanded(
child: Text1(
title: data["speciality"] ?? data['spl'],
fontweight: FontWeight.normal,
txtfont: isTablet ? 20 : 14,
),
),
],
),
Row(
children: [
Text1(
title: data["State"] ?? '',
fontweight: FontWeight.normal,
txtfont: 14,
),
SizedBox(
width: 3.0,
),
Expanded(
child: Text1(
title: data["Country"] ?? '',
fontweight: FontWeight.normal,
txtfont: 14,
),
),
],
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.only(left: 10.0),
child: Text1(
title: "Added by Pooja k",
fontweight: FontWeight.normal,
txtfont: 14,
),
),
Padding(
padding: EdgeInsets.only(right: 10.0),
child: Text1(
title: "Added on 01/07/2023",
fontweight: FontWeight.normal,
txtfont: 14,
),
)
],
),
Divider(),
],
);
},
),
);
}
Future<void> offlineProfileStore(List<String> selectedIndices) async {
for (int i = 0; i < selectedIndices.length; i++) {
print('The id id : ${selectedIndices[i]}');
Map<String, dynamic>? row =
findRecordById(displayedHCPList, selectedIndices[i]);
print("Storingggg_isss:Row $row");
await addKolInfo(row);
await Provider.of<AffiliationsProvider>(context, listen: false)
.storeAff(row["id"]);
await Provider.of<PublicatioProvider>(context, listen: false)
.storePub(row["id"]);
await Provider.of<EventProvider>(context, listen: false)
.storeEvent(row["id"]);
await Provider.of<TrialsProvider>(context, listen: false)
.storeTrials(row["id"]);
await Provider.of<LocationProvider>(context, listen: false)
.storeLoc(row["id"]);
await Provider.of<PhonenoProvider>(context, listen: false)
.storePno(row["id"]);
await Provider.of<EmailProvider>(context, listen: false)
.storeEmail(row["id"]);
await Provider.of<EducationProvider>(context, listen: false)
.storeEdu(row["id"]);
await Provider.of<AwardProvider>(context, listen: false)
.storeAwa(row["id"]);
await Provider.of<CertificateProvider>(context, listen: false)
.storeCer(row["id"]);
await Provider.of<PatentProvider>(context, listen: false)
.storePet(row["id"]);
await Provider.of<NIHGrantsProvider>(context, listen: false)
.storeNih(row["id"]);
await Provider.of<ProcedureProvider>(context, listen: false)
.storePro(row["id"]);
await Provider.of<TrainigProvider>(context, listen: false)
.storeTraining(row["id"]);
await Provider.of<SpekerEvalutionProvider>(context, listen: false)
.storeSpeaker(row["id"]);
}
}
contactsBottomdailog() {
return Align(
alignment: Alignment.bottomCenter,
child: longpress
? Container(
color: const Color.fromARGB(255, 251, 242, 242),
width: MediaQuery.of(context).size.width,
height: 200.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
!_switchValue
? GestureDetector(
onTap: () async {
print("Selected: ${_selectedIndices}");
print("Selected: ${_selectedIndices.length}");
for (int i = 0; i < _selectedIndices.length; i++) {
Map<String, dynamic>? row = findRecordById(
displayedHCPList, _selectedIndices[i]);
print("StoringgggMyContact_isss_isss:Row $row");
await HiveFunctions.savemyContact(row);
}
_showMyDialog(
"Selected contact has been added to my contacts ");
},
child: Row(
children: [
const Padding(
padding: EdgeInsets.all(15.0),
child: Icon(
Icons.add,
color: Colors.green,
),
),
Text1(
title: 'Add to My Contacts',
txtcolor: Colors.black,
txtfont: 14.0),
],
),
)
: GestureDetector(
onTap: () async {
print(
"SelectedRemoveee: ${_selectedremoveIndices}");
print("Selected: ${_selectedremoveIndices.length}");
for (int i = 0;
i < _selectedremoveIndices.length;
i++) {
await HiveFunctions.deleteUser11(
_selectedremoveIndices[i]);
}
setState(() {});
_showMyDialog("selected contact has been removed");
},
child: const Row(
children: [
Padding(
padding: EdgeInsets.all(15.0),
child: Icon(
Icons.remove,
color: Colors.green,
),
),
Text(
'Remove from My Contacts',
style: TextStyle(color: Colors.black),
),
],
),
),
Row(
children: [
const Padding(
padding: EdgeInsets.all(15.0),
child: Icon(
Icons.download,
color: Colors.blue,
),
),
GestureDetector(
onTap: () {},
child: Text1(
title: 'Download',
txtcolor: Colors.black,
),
),
],
),
GestureDetector(
onTap: () {
setState(() {
longpress = false;
_selectedIndices.clear();
_selectedremoveIndices.clear();
});
},
child: Row(
children: [
const Padding(
padding: EdgeInsets.all(15.0),
child: Icon(
Icons.close,
color: Colors.red,
),
),
Text1(
title: 'Cancel',
txtcolor: Colors.black,
),
],
),
),
Visibility(
visible: !_switchValue ? true : false,
child: Expanded(
child: GestureDetector(
onTap: () async {
print("Selected: ${_selectedIndices}");
offlineProfileStore(_selectedIndices);
_showMyDialog(
"selected contact has been added to offline");
setState(() {});
},
child: const Row(
children: [
Padding(
padding: EdgeInsets.all(15.0),
child: Icon(
Icons.save,
color: Colors.deepOrange,
),
),
Padding(
padding: EdgeInsets.only(top: 15.0),
child: Text(
'Save Offline',
style: TextStyle(color: Colors.black),
),
),
],
),
),
),
),
],
),
)
: Container(),
);
}
Future<void> initConnectivity() async {
late List<ConnectivityResult> result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await _connectivity.checkConnectivity();
} on PlatformException catch (e) {
developer.log('Couldn\'t check connectivity status', error: e);
return;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) {
return Future.value(null);
}
return _updateConnectionStatus(result);
}
Future<void> _updateConnectionStatus(List<ConnectivityResult> result) async {
setState(() {
_connectionStatus = result;
});
// ignore: avoid_print
print('Connectivity changed: $_connectionStatus');
}
}