DiscoverModule/lib/ui_screen/new_contacts.dart

299 lines
10 KiB
Dart
Raw Normal View History

2024-07-05 08:48:29 +00:00
import 'package:discover_module/provider_class/hcp%20_provider.dart';
import 'package:discover_module/ui_screen/interactionform/NewtworkConnectivity.dart';
import 'package:discover_module/ui_screen/new_profile.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_profile_picture/flutter_profile_picture.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'package:discover_module/ui_screen/profile.dart';
class Contacts1 extends StatefulWidget {
const Contacts1({Key? key}) : super(key: key);
@override
State<Contacts1> createState() => _Contacts1State();
}
class _Contacts1State extends State<Contacts1> {
final _contactBox = Hive.box("mycontact");
bool _switchValue = false;
bool isOnline2 = true;
@override
void initState() {
super.initState();
setupConnectivityListener();
getCall();
}
Future<void> setupConnectivityListener() async {
while (true) {
bool isOnline = await NetworkConnectivity().isInternetAvailable();
print('Internet contact available: $isOnline');
await Future.delayed(Duration(seconds: 2));
if (mounted) {
setState(() {
isOnline2 = isOnline;
});
}
}
}
// @override
// void dispose() {
// // TODO: implement dispose
// }
void getCall() async {
await Provider.of<hcpProvider>(context, listen: false).getHCPProvider();
}
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Color.fromARGB(255, 0, 71, 132)));
return SafeArea(
child: Scaffold(
body: Consumer<hcpProvider>(
builder: (context, value, child) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 45.0),
child: Text(
_switchValue ? "My Contacts" : "All Contacts",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
),
),
),
),
Row(
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,
),
),
CupertinoSwitch(
activeColor: Color.fromARGB(255, 0, 71, 132),
value: _switchValue,
onChanged: (value) {
setState(() {
_switchValue = value;
});
},
),
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: !_switchValue
? const Text(
'My',
style: TextStyle(
fontSize: 12,
decoration: TextDecoration.lineThrough,
decorationThickness: 0.85,
),
)
: const Text(
'My',
style: TextStyle(
fontSize: 12,
),
),
)
],
),
],
),
2024-07-12 08:40:20 +00:00
!_switchValue ? Listdisplay(value) : Listdisplay1(_contactBox)
// Expanded(
// child: ListView.builder(
// itemCount: _contactBox.values.length,
// itemBuilder: (BuildContext context, int index) {
// var data = _contactBox.get(index);
// print(":data_is: $data");
// return ListTile(
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => NewProfile(
// text: data!,
// ),
// ),
// );
// },
// leading: ProfilePicture(
// name: data["name"],
// radius: 20,
// fontsize: 12,
// ),
// title: Text(
// data["name"],
// style: TextStyle(
// fontSize: 18.0,
// fontWeight: FontWeight.bold,
// ),
// ),
// subtitle: Text(
// "Added by Pooja.K",
// style: TextStyle(
// fontSize: 14.0,
// fontWeight: FontWeight.normal,
// ),
// ),
// );
// },
// ),
// ),
],
);
},
),
),
);
}
2024-07-05 08:48:29 +00:00
2024-07-12 08:40:20 +00:00
Listdisplay(hcpProvider value) {
return Expanded(
child: ListView.builder(
itemCount: value.list.length,
itemBuilder: (BuildContext context, int index) {
var data = value.list[index];
return Column(
children: [
ListTile(
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => Profile(
// text: data,
// ),
// ),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => NewProfile(text: data)));
},
leading: data["img_path"] == null
? ProfilePicture(
name: data["name"],
radius: 20,
fontsize: 12,
)
: ClipOval(
child: SizedBox.fromSize(
size: Size.fromRadius(20),
child: Image.network(data["img_path"],
fit: BoxFit.cover),
2024-07-05 08:48:29 +00:00
),
2024-07-12 08:40:20 +00:00
),
trailing: Text("Added by\nPooja k"),
title: Text(
"${data["name"]}",
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
"${data["speciality"]}\n${data["addr"]},",
style: const TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.normal,
),
),
),
Divider(),
],
);
},
),
);
}
Listdisplay1(Box value) {
return Expanded(
child: ListView.builder(
itemCount: value.values.length,
itemBuilder: (BuildContext context, int index) {
var data = value.get(index);
return Column(
children: [
ListTile(
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => Profile(
// text: data,
// ),
// ),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => NewProfile(text: data)));
},
leading: data["img_path"] == null
? ProfilePicture(
name: data["name"],
radius: 20,
fontsize: 12,
2024-07-05 08:48:29 +00:00
)
2024-07-12 08:40:20 +00:00
: ClipOval(
child: SizedBox.fromSize(
size: Size.fromRadius(20),
child: Image.network(data["img_path"],
fit: BoxFit.cover),
2024-07-05 08:48:29 +00:00
),
),
2024-07-12 08:40:20 +00:00
trailing: Text("Added by\nPooja k"),
title: Text(
"${data["name"]}",
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
"${data["speciality"]}\n${data["addr"]},",
style: const TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.normal,
),
),
),
Divider(),
],
);
},
2024-07-05 08:48:29 +00:00
),
);
}
}