import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:discover_module/constants.dart'; import 'package:discover_module/hive_fun.dart'; import 'package:discover_module/provider_class/hcp%20_provider.dart'; import 'package:discover_module/ui_screen/filters_menu.dart'; import 'package:discover_module/ui_screen/interactionform/util.dart'; import 'package:discover_module/ui_screen/new_new_profile.dart'; import 'package:discover_module/ui_screen/new_new_profile_offline.dart'; import 'package:dropdown_button2/dropdown_button2.dart'; import 'package:dropdownfield2/dropdownfield2.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_svg/svg.dart'; import 'package:provider/provider.dart'; import 'package:flutter/services.dart'; import 'package:flutter_profile_picture/flutter_profile_picture.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:discover_module/ui_screen/interactionform/NewtworkConnectivity.dart'; class Contacts1 extends StatefulWidget { const Contacts1({Key? key}) : super(key: key); @override State createState() => _Contacts1State(); } class _Contacts1State extends State { final GlobalKey _scaffoldKey = GlobalKey(); // final contactBox = Hive.box("mycontact"); bool _switchValue = false; bool isOnline2 = true; final TextEditingController _searchController = TextEditingController(); List ddlist = ["aaaa", 'bbb']; // List ddlist = ['Option 1', 'Option 2', 'Option 3']; String _selectedValue = ''; String? _selectedValue1; String dropdownvalue = 'Profile Type'; // List of items in our dropdown menu var items = [ 'Profile Type', 'HCP Name', 'Speciality', 'Country', 'Region', 'State', 'City', 'List', 'Organization', 'Event', ]; bool isSearchClickd = false; final List _items = ['Option 1', 'Option 2', 'Option 3']; TextEditingController textEditingController = TextEditingController(); List displayedHCPList = []; bool ActiveConnection = false; String T = ""; bool isChecked = false; //final Set _selectedIndices = Set(); final List _selectedIndices = []; final List _selectedremoveIndices = []; bool longpress = false; bool longpressmy = false; // Future CheckUserConnection() async { // try { // final result = await InternetAddress.lookup('google.com'); // if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) { // setState(() { // ActiveConnection = true; // T = "Turn off the data and repress again"; // print("Isssss Off $ActiveConnection"); // Provider.of(context, listen: false).getHCPProvider(); // }); // } // } on SocketException catch (_) { // setState(() { // ActiveConnection = false; // T = "Turn On the data and repress again"; // print("Isssss Off $ActiveConnection"); // Provider.of(context, listen: false).getHCPProviderHive(); // }); // } // } @override void initState() { super.initState(); // CheckUserConnection(); Provider.of(context, listen: false).getHCPProvider(); // HiveFunctions.getAllUsers11(); //Provider.of(context, listen: false).getHCPProviderHive(); //print("Get_hcp_dataaaL ${HiveFunctions.gethcpdata()}"); // getDropdownlist(); } @override Widget build(BuildContext context) { print("ProfileType $dropdownvalue, $_selectedValue1"); // print("all StoredUser: ${HiveFunctions.getAllUsers11()}"); if (_selectedValue1 == "Profile Type") { print("PPPP11"); setState(() { ddlist = [ "All Profile", 'Full Profile', 'Basic Profile', ]; }); } else if (_selectedValue1 == "HCP Name") { print("kkk"); setState(() { ddlist = [ 'Abraham, William', "Abbas,Samer", 'Butler, Javed', ]; }); } else if (_selectedValue1 == "Speciality") { print("kkk"); setState(() { ddlist = [ "Cardiovascular Disease", 'Interventional Cardiology', "Cardiovascular Disease", ]; }); } else if (_selectedValue1 == "Country") { print("kkk"); setState(() { ddlist = [ "United States", "United States", "United States", ]; }); } else if (_selectedValue1 == "State") { print("kkk"); setState(() { ddlist = [ "Karnataka", 'Karnataka', 'Karnataka', ]; }); } else if (_selectedValue1 == "City") { print("kkk"); setState(() { ddlist = [ "Hubli", 'Hubli', 'Hubli', ]; }); } SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle(statusBarColor: Color.fromARGB(255, 0, 71, 132))); return SafeArea( child: Scaffold( key: _scaffoldKey, // Assign the key to the Scaffold // backgroundColor: const Color.fromARGB(255, 246, 248, 252), // backgroundColor: Color.fromARGB(255, 255, 242, 0.92), 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, ), ), ), ) : Text("Contacts"), actions: [ IconButton( onPressed: () { setState(() { isSearchClickd = !isSearchClickd; if (!isSearchClickd) { _searchController.clear(); } }); }, icon: Icon(isSearchClickd ? Icons.close : Icons.search)) ], ), endDrawer: Drawer( // width: MediaQuery.of(context).size.width * 99.2, child: listdata(), ), body: Consumer( builder: (context, hcpProvider, child) { print("_selectedValueConsumerConsumer_isss: $_selectedValue"); if (_selectedValue.isNotEmpty) { _searchController.text = _selectedValue; } displayedHCPList = hcpProvider.searchHCP(_searchController.text); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, //mainAxisSize: MainAxisSize.min, children: [ // _switchValue // ? const Text( // 'All', // style: TextStyle( // fontSize: 12, // decoration: TextDecoration.lineThrough, // decorationThickness: 0.85, // ), // ) // : const Text( // 'All', // style: TextStyle( // fontSize: 12, // ), // ), Container( child: 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 ? const Text( 'My Contacts', style: TextStyle( fontSize: 15, color: Colors.grey), ) : const Text( 'My Contacts', style: TextStyle( fontSize: 15, ), ), ) ], ), ), Padding( padding: const EdgeInsets.only(right: 8.0), child: Row( children: [ Text("Filters"), IconButton( onPressed: () { _scaffoldKey.currentState?.openEndDrawer(); }, icon: Icon( Icons.sort, size: 30, )), ], ), ) ], ), // Row( // children: [ // Expanded( // child: Text( // _switchValue ? "My Contacts" : "All Contacts", // textAlign: TextAlign.center, // style: TextStyle( // fontSize: 20.0, // fontWeight: FontWeight.w500, // ), // ), // ), // ], // ), // Padding( // padding: const EdgeInsets.only( // top: 8.0, bottom: 8.0, left: 20.0, right: 20.0), // child: Center( // child: TextField( // controller: _searchController, // onChanged: (value) { // setState(() {}); // }, // decoration: InputDecoration( // fillColor: Constants.k2color, // contentPadding: EdgeInsets.symmetric(vertical: 9.0), // border: OutlineInputBorder(), // labelText: ' Search', // prefixIcon: Icon( // Icons.search, // ), // ), // ), // ), // ), SizedBox( height: 5, ), !_switchValue ? Expanded( child: ListView.builder( itemCount: displayedHCPList.length, itemBuilder: (BuildContext context, int index) { var data = displayedHCPList[index]; print("CheckinggggImage_path: ${data['img_path']}"); return Column( children: [ ListTile( onLongPress: () { print("LongPresss"); setState(() { longpress = true; }); }, onTap: () async { print("Check_data = ${data["Location"]}"); 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: Size.fromRadius(30), child: CachedNetworkImage( imageUrl: data["img_path"], imageBuilder: (context, imageProvider) => Container( decoration: BoxDecoration( image: DecorationImage( image: imageProvider, fit: BoxFit.fill, ), ), ), // placeholder: (context, url) => // CircularProgressIndicator(), // errorWidget: (context, url, error) => // Icon(Icons.error), ), ), ), trailing: Visibility( visible: longpress, child: Checkbox( value: _selectedIndices .contains(data["uid"]), onChanged: (value) { // setState(() { // _selectedIndices.add(data["id"]); // // isChecked = value!; // }); setState(() { if (value!) { _selectedIndices.add(data["uid"]); } else { _selectedIndices .remove(data["uid"]); } print( "id_total: ${_selectedIndices}"); }); }), ), title: Text( "${data["name"]}", style: TextStyle( fontSize: isTablet ? 22 : 16, fontWeight: FontWeight.bold, ), ), subtitle: Column( children: [ Row( children: [ Expanded( child: Text( "${data["speciality"] ?? data['spl']},", style: TextStyle( fontSize: isTablet ? 20 : 14, fontWeight: FontWeight.normal, ), ), ), ], ), Row( children: [ Text( "${data["State"] ?? ""},", style: const TextStyle( fontSize: 14.0, fontWeight: FontWeight.normal, ), ), SizedBox( width: 3.0, ), Expanded( child: Text( "${data["Country"] ?? ""}", style: const TextStyle( fontSize: 14.0, fontWeight: FontWeight.normal, ), ), ), ], ), // Row( // children: [ // Text( // "Added by Pooja k\nAdded on 01/07/2023", // style: const TextStyle( // fontSize: 12.0, // fontWeight: FontWeight.normal, // ), // ) // ], // ) ], ), ), const Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( padding: EdgeInsets.only(left: 10.0), child: Text( "Added by Pooja k", style: TextStyle( fontSize: 12.0, fontWeight: FontWeight.normal, ), ), ), Padding( padding: EdgeInsets.only(right: 10.0), child: Text( "Added on 01/07/2023", style: TextStyle( fontSize: 12.0, fontWeight: FontWeight.normal, ), ), ) ], ), Divider(), ], ); }, ), ) : Expanded( child: ListView.builder( itemCount: HiveFunctions.getAllUsers11().length, itemBuilder: (BuildContext context, int index) { var data = HiveFunctions.getAllUsers11()[index]; print("CheckinggggImage_path: ${data['img_path']}"); print( "CheckinggggImage_path: ${data['name']},${data['inid']}"); return Column( children: [ ListTile( onLongPress: () { print("LongPresss"); setState(() { longpressmy = true; }); }, onTap: () async { print("Check_data = $data"); Navigator.push( context, MaterialPageRoute( builder: (context) => NewProfile1(text: data), ), ); }, leading: data["img_path"] == "" ? ProfilePicture( name: data["name"], radius: 30, fontsize: 12, ) : ClipOval( child: SizedBox.fromSize( size: Size.fromRadius(30), child: CachedNetworkImage( imageUrl: data["img_path"], imageBuilder: (context, imageProvider) => Container( decoration: BoxDecoration( image: DecorationImage( image: imageProvider, fit: BoxFit.fill, ), ), ), // placeholder: (context, url) => // CircularProgressIndicator(), // errorWidget: (context, url, error) => // Icon(Icons.error), ), ), ), trailing: Visibility( visible: longpressmy, child: 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: Text( "${data["name"]}", style: TextStyle( fontSize: isTablet ? 22 : 16, fontWeight: FontWeight.bold, ), ), subtitle: Column( children: [ Row( children: [ Expanded( child: Text( "${data["speciality"] ?? data['spl']},", style: TextStyle( fontSize: isTablet ? 20 : 14, fontWeight: FontWeight.normal, ), ), ), ], ), Row( children: [ Text( "${data["addr"]},", style: const TextStyle( fontSize: 14.0, fontWeight: FontWeight.normal, ), ), ], ), ], ), ), const Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( padding: EdgeInsets.only(left: 10.0), child: Text( "Added by Pooja k", style: TextStyle( fontSize: 12.0, fontWeight: FontWeight.normal, ), ), ), Padding( padding: EdgeInsets.only(right: 10.0), child: Text( "Added on 01/07/2023", style: TextStyle( fontSize: 12.0, fontWeight: FontWeight.normal, ), ), ) ], ), Divider(), ], ); }, ), ), !_switchValue ? 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: [ GestureDetector( onTap: () async { print("Selected: ${_selectedIndices}"); print( "Selected: ${_selectedIndices.length}"); for (int i = 0; i < _selectedIndices.length; i++) { print( 'The id id : ${_selectedIndices[i]}'); //List<_Row> _rows = []; final row = displayedHCPList[ _selectedIndices[i] - 1]; var data = displayedHCPList[i]; print( "checking_value_istrends: ${_selectedIndices[i]},${row["name"]}, ${row["id"]}"); int autoIncrementKey1 = await getNextAutoIncrementValue(); print(autoIncrementKey1); HiveFunctions.createUser({ "inid": autoIncrementKey1, "id": autoIncrementKey1, "name": row["name"], "org": "med", "addr": row["addr"], "phone": row["phone_no"], "phone_no": row["phone_no"], "email": row["email"], "summarry": row["summarry"], "speciality": row["speciality"], "sub_speciality": row["sub_speciality"], "img_path": row["img_path"], }); } _showMyDialog( "Selected contact has been added to my contacts "); }, child: Row( children: [ Padding( padding: const EdgeInsets.all(15.0), child: Icon( Icons.add, color: Colors.green, ), ), Text( 'Add to My Contacts', style: TextStyle( color: Colors.black, fontSize: 14.0), ), ], ), ), Row( children: [ Padding( padding: const EdgeInsets.all(15.0), child: Icon( Icons.download, color: Colors.blue, ), ), GestureDetector( onTap: () {}, child: Text( 'Download', style: TextStyle(color: Colors.black), ), ), ], ), GestureDetector( onTap: () { setState(() { longpress = false; _selectedIndices.clear(); _selectedremoveIndices.clear(); }); }, child: const Row( children: [ Padding( padding: EdgeInsets.all(15.0), child: Icon( Icons.close, color: Colors.red, ), ), Text( 'Cancel', style: TextStyle(color: Colors.black), ), ], ), ), ], ), ) : Container(), ) : Align( alignment: Alignment.bottomCenter, child: longpressmy ? Container( color: const Color.fromARGB(255, 251, 242, 242), width: MediaQuery.of(context).size.width, height: 200.0, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( onTap: () async { print( "SelectedRemoveee: ${_selectedremoveIndices}"); print( "Selected: ${_selectedremoveIndices.length}"); for (int i = 0; i < _selectedremoveIndices.length; i++) { print( 'The id id : ${_selectedremoveIndices[i]}'); //List<_Row> _rows = []; // final row = displayedHCPList[ // _selectedremoveIndices[i] - 1]; // var data = displayedHCPList[i]; final row = await HiveFunctions.getuser( _selectedremoveIndices[i]); // var data = HiveFunctions.getuser()[i]; print("Delete_Row ${row[i]}"); print("Delete_Row ${row[i]["inid"]}"); // print( // "checking_valueRemove_istrends: ${_selectedremoveIndices[i]},${row["name"]}, ${row["id"]},${row["inid"]}"); //HiveFunctions.addno(_selectedIndices[i]); // HiveFunctions.removeno(_selectedremoveIndices[i]); final row1 = await HiveFunctions.deleteUser11( row[i]["inid"]); setState(() {}); // HiveFunctions.deleteUser(_selectedremoveIndices); } _showMyDialog( "selected contact has been removed"); }, child: Row( children: [ Padding( padding: const EdgeInsets.all(15.0), child: Icon( Icons.remove, color: Colors.green, ), ), Text( 'Remove from My Contacts', style: TextStyle(color: Colors.black), ), ], ), ), Row( children: [ Padding( padding: const EdgeInsets.all(15.0), child: Icon( Icons.download, color: Colors.blue, ), ), GestureDetector( onTap: () {}, child: Text( 'Download', style: TextStyle(color: Colors.black), ), ), ], ), GestureDetector( onTap: () { setState(() { longpressmy = false; _selectedIndices.clear(); _selectedremoveIndices.clear(); }); }, child: Row( children: [ Padding( padding: const EdgeInsets.all(15.0), child: Icon( Icons.close, color: Colors.red, ), ), Text( 'Cancel', style: TextStyle( color: Constants.k2color), ), ], ), ), ], ), ) : Container(), ), ], ); }, ), ), ); } listdata() { return ListView( children: [ // DrawerHeader removed ListTile( title: Padding( padding: const EdgeInsets.all(8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Icon( Icons.sort, size: 30.0, ), const Text( "Filters", style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold), ), GestureDetector( onTap: () { Navigator.pop(context); // print("hiii"); }, child: const Icon(Icons.cancel)) ], ), ), ), ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ OutlinedButton( onPressed: () { //setState(() {}); Navigator.push( context, MaterialPageRoute(builder: (context) => Contacts1()), ).then((value) => setState(() {})); print("refresh done "); // }) }, child: Text( 'Reset Filter', style: TextStyle(color: Constants.k2color), ), style: OutlinedButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), ), ], ), ), // ListTile( // title: SizedBox( // width: MediaQuery.of(context).size.width, // child: DropdownButtonFormField( // decoration: InputDecoration( // enabledBorder: OutlineInputBorder( // borderRadius: BorderRadius.circular(10), // borderSide: BorderSide(width: 1, color: Colors.black)), // focusedBorder: OutlineInputBorder( // borderRadius: BorderRadius.circular(10), // borderSide: BorderSide(width: 1, color: Colors.black), // ), // ), // value: dropdownvalue, // items: items.map((String items) { // return DropdownMenuItem( // value: items, // child: Text( // items, // style: TextStyle(fontSize: 14.0), // ), // ); // }).toList(), // // After selecting the desired option,it will // // change button value to selected value // onChanged: (String? newValue) { // setState(() { // dropdownvalue = newValue!; // }); // }, // ), // ), // ), ListTile( title: DropdownButtonHideUnderline( child: DropdownButtonFormField2( // decoration: InputDecoration( // border: OutlineInputBorder(), // labelText: 'Select an option', // ), hint: Text("Select the Type"), decoration: InputDecoration( // Add Horizontal padding using menuItemStyleData.padding so it matches // the menu padding when button's width is not specified. isDense: true, contentPadding: const EdgeInsets.symmetric(vertical: 9), border: OutlineInputBorder( borderRadius: BorderRadius.circular(10.0), ), // Add more decoration.. ), isExpanded: true, value: _selectedValue1, items: items.map((String item) { return DropdownMenuItem( value: item, child: Text(item), ); }).toList(), onChanged: (String? newValue) { setState(() { _selectedValue1 = newValue; }); }, // buttonStyleData: ButtonStyleData( // height: 50, // padding: EdgeInsets.symmetric(horizontal: 14), // decoration: BoxDecoration( // borderRadius: BorderRadius.circular(10), // border: Border.all(color: Colors.grey), // ), // ), buttonStyleData: const ButtonStyleData( padding: EdgeInsets.symmetric(horizontal: 16), height: 50, width: 200, ), dropdownStyleData: DropdownStyleData( maxHeight: 200, decoration: BoxDecoration( borderRadius: BorderRadius.circular(14), ), ), menuItemStyleData: const MenuItemStyleData( height: 40, ), dropdownSearchData: DropdownSearchData( searchController: textEditingController, searchInnerWidgetHeight: 50, searchInnerWidget: Container( height: 50, // padding: const EdgeInsets.only( // top: 8, // bottom: 4, // right: 8, // left: 8, // ), child: TextFormField( expands: true, maxLines: null, controller: textEditingController, decoration: InputDecoration( isDense: true, contentPadding: const EdgeInsets.symmetric( horizontal: 10, vertical: 18, ), hintText: 'Search for an item...', hintStyle: const TextStyle(fontSize: 12), border: OutlineInputBorder( borderRadius: BorderRadius.circular(10.0), ), ), ), ), searchMatchFn: (item, searchValue) { final itemString = item.value.toString().toLowerCase(); final searchString = searchValue.toLowerCase(); return itemString.contains(searchString); }, ), onMenuStateChange: (isOpen) { if (!isOpen) { textEditingController.clear(); } }, iconStyleData: IconStyleData( icon: Icon(Icons.arrow_drop_down), iconSize: 20, ), ), ), ), ListTile( title: Container( decoration: BoxDecoration( border: Border.all(color: Colors.black), borderRadius: BorderRadius.circular(10)), child: Padding( padding: const EdgeInsets.all(3.5), child: DropDownField( hintText: 'Select an option', items: ddlist, onValueChanged: (newValue) { setState(() { _selectedValue = newValue; }); }, value: _selectedValue, ), ), ), ), // ListTile( // title: Padding( // padding: const EdgeInsets.only(left: 35.0, right: 35.0), // child: OutlinedButton( // onPressed: () async { // filterss(_selectedValue); // }, // child: Text( // 'Filter', // style: TextStyle(color: Constants.k2color), // ), // style: OutlinedButton.styleFrom( // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(12), // ), // ), // ), // ), // ) ], ); } filterss(String selectedValue) async { setState(() { print("_selectedValue_isss: $_selectedValue"); }); } Future _showMyDialog(String data) async { return showDialog( context: context, barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( title: const Text('Successfully'), content: SingleChildScrollView( child: ListBody( children: [ // Text('This is a demo alert dialog.'), Text(data), ], ), ), actions: [ TextButton( child: const Text('Ok'), onPressed: () { Navigator.of(context).pop(); setState(() { _selectedIndices.clear(); _selectedremoveIndices.clear(); longpress = false; longpressmy = false; }); }, ), ], ); }, ); } Future getNextAutoIncrementValue() async { var counterBox = await Hive.openBox('counterBox'); if (!counterBox.containsKey('counter')) { counterBox.put('counter', 0); } int? counter = counterBox.get('counter'); counterBox.put('counter', counter! + 1); await counterBox.close(); return counter; } }