DiscoverModule/lib/ui_screen/new_contacts.dart

683 lines
24 KiB
Dart

import 'package:discover_module/constants.dart';
import 'package:discover_module/provider_class/hcp%20_provider.dart';
import 'package:discover_module/ui_screen/filters_menu.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/profile.dart';
import 'package:discover_module/ui_screen/new_profile.dart';
import 'package:discover_module/ui_screen/interactionform/NewtworkConnectivity.dart';
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>();
final _contactBox = Hive.box("mycontact");
bool _switchValue = false;
bool isOnline2 = true;
final TextEditingController _searchController = TextEditingController();
List<String> ddlist = ["aaaa", 'bbb'];
// List<String> 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<String> _items = ['Option 1', 'Option 2', 'Option 3'];
TextEditingController textEditingController = TextEditingController();
List displayedHCPList = [];
@override
void initState() {
super.initState();
Provider.of<hcpProvider>(context, listen: false).getHCPProvider();
// getDropdownlist();
}
// getDropdownlist() {
// final provider =
// Provider.of<hcpProvider>(context, listen: false).getHCPProvider();
// final datta = provider.list;
// print("Providerrrrr_is ${datta}");
// }
@override
Widget build(BuildContext context) {
print("ProfileType $dropdownvalue, $_selectedValue1");
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<hcpProvider>(
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,
),
Expanded(
child: ListView.builder(
itemCount: displayedHCPList.length,
itemBuilder: (BuildContext context, int index) {
var data = displayedHCPList[index];
return Column(
children: [
ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewProfile(text: data),
),
);
},
leading: data["img_path"] == null
? ProfilePicture(
name: data["name"],
radius: 20,
fontsize: 12,
)
: ClipOval(
child: SizedBox.fromSize(
size: Size.fromRadius(30), // Image radius
child: Image.network(data["img_path"],
fit: BoxFit.fill),
),
),
// trailing: Icon(
// Icons.person_add_rounded,
// color: Constants.k2color,
// size: 30.0,
// ),
title: Text(
"${data["name"]}",
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
subtitle: Column(
children: [
Row(
children: [
Expanded(
child: Text(
"${data["speciality"]},",
style: const TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.normal,
),
),
),
],
),
Row(
children: [
Text(
"${data["addr"]},",
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(),
],
);
},
),
),
],
);
},
),
),
);
}
listdata() {
return ListView(
children: <Widget>[
// 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<String>(
// 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<String>(
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");
});
}
}