import 'package:discover_module/contacts_module/custom_widget/show_alert.dart'; import 'package:discover_module/contacts_module/custom_widget/text.dart'; import 'package:discover_module/contacts_module/model_class/awards_model.dart'; import 'package:discover_module/contacts_module/provider_class/k2_provider/kol_add_provider.dart'; import 'package:discover_module/contacts_module/provider_class/k2_provider/kol_viewnotes.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; class ViewNotes extends StatefulWidget { const ViewNotes({super.key}); @override State createState() => _ViewNotesState(); } class _ViewNotesState extends State { // late FetchNotes; List notess = []; var _isLoading = false; // var events; late HcpNotesFecth fetchNotesProviderK2; TextEditingController updatenoteController = TextEditingController(); @override void initState() { // TODO: implement initState super.initState(); //fetchhcpnotes(); fetchNotesProviderK2 = HcpNotesFecth(); } // Future fetchhcpnotes() async { // print("Hiiiiii"); // var notesprovider = Provider.of(context, listen: false); // await notesprovider.fetchhcpnotes(); // var getnotes = notesprovider.ListNotes; // setState(() { // notess = getnotes; // }); // } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Notes'), ), body: ChangeNotifierProvider( create: (context) => fetchNotesProviderK2..fetchhcpnotes(), child: Consumer(builder: (context, hcpnotes, child) { return NotificationListener( onNotification: (ScrollNotification scrollinfo) { if (scrollinfo.metrics.pixels == scrollinfo.metrics.maxScrollExtent && !fetchNotesProviderK2.isLoading) { hcpnotes.fetchhcpnotes(); } return false; }, child: ListView.builder( itemCount: hcpnotes.ListNotes.length + (hcpnotes.hasMore ? 1 : 0), // +(events.hasMore ? 1 : 0), itemBuilder: (context, index) { if (index == hcpnotes.ListNotes.length) { return const Center(child: CircularProgressIndicator()); } var data = hcpnotes.ListNotes[index]; // print("I_amCheckingggggg12345: ${data.name}"); return ListTile( title: Text1(title: "Note : " + data.userNote), subtitle: Text1(title: "Created by : " + data.createdByUser), trailing: Wrap( spacing: -16, children: [ IconButton( icon: const Icon(Icons.edit), onPressed: () { print("Clickedd: ${data.userNote}"); //updatenoteController.text = data.userNote; showDialog( context: context, builder: (_) { return updatedata(data); // return Alert( // data: "Added ", // onPressed: () { // noteController.clear(); // Navigator.of(context).pop(); // }, // ); }); }, ), IconButton( icon: const Icon( Icons.delete, //color: Colors.redAccent, ), onPressed: () { showDialog( context: context, builder: (_) { //return updatedata(data); return AlertDialog( // title: Text1( // title: "Alert", // txtfont: 22.0, // ), content: Text1( title: data.userNote, txtfont: 18.0, ), actions: [ TextButton( onPressed: () {}, child: Text("Cancel")), TextButton( onPressed: () async { Navigator.of(context).pop(); var addnoteprovider = Provider .of( context, listen: false); await addnoteprovider .deletenotes(data.uniqueId); showDialog( context: context, builder: (_) { return Alert( data: "Deleted ", onPressed: () { //noteController.clear(); Navigator.of(context) .pop(); }, ); }); }, child: Text("Delete")) ], ); }); }, ), ], ), ); })); }), )); } updatedata(data) { return AlertDialog( title: Text1( title: "Alert", txtfont: 22.0, ), content: TextField( controller: updatenoteController..text = data.userNote, //controller: TextEditingController()..text = data, decoration: InputDecoration( border: OutlineInputBorder( borderRadius: BorderRadius.circular(8.0), ), hintText: 'Write your note here', contentPadding: EdgeInsets.all(16.0), ), maxLines: null, // Allows the TextField to expand vertically ), actions: [ TextButton( onPressed: () async { print("Iam OKKK ${updatenoteController.text}"); print("Iam OKKK ${data.uniqueId}"); var addnoteprovider = Provider.of(context, listen: false); await addnoteprovider.addnotes( updatenoteController.text, data.uniqueId); showDialog( context: context, builder: (_) { return Alert( data: "Updated ", onPressed: () async { // noteController.clear(); // Refresh the notes list setState(() {}); Navigator.of(context).pop(); }, ); }); }, child: Text("Ok")), TextButton( onPressed: () { print("Iam Cancel"); Navigator.pop(context); }, child: Text("Cancel")) ], ); } } // import 'package:discover_module/contacts_module/model_class/awards_model.dart'; // import 'package:discover_module/contacts_module/provider_class/k2_provider/kol_viewnotes.dart'; // import 'package:flutter/material.dart'; // import 'package:provider/provider.dart'; // class ViewNotes extends StatefulWidget { // const ViewNotes({super.key}); // @override // State createState() => _ViewNotesState(); // } // class _ViewNotesState extends State { // // late FetchNotes; // List notess = []; // @override // void initState() { // // TODO: implement initState // super.initState(); // fetchhcpnotes(); // } // Future fetchhcpnotes() async { // print("Hiiiiii"); // var notesprovider = Provider.of(context, listen: false); // await notesprovider.fetchhcpnotes(); // var getnotes = notesprovider.ListNotes; // setState(() { // notess = getnotes; // }); // } // @override // Widget build(BuildContext context) { // return Scaffold( // appBar: AppBar( // title: Text('Notes'), // ), // body: ListView.builder( // itemCount: notess.length, // itemBuilder: (context, index) { // var data = notess[index]; // return Text(data.userNote); // })); // } // }