- Get link
- X
- Other Apps
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
import 'package:toodos/modals/todos.dart';
import '../export/export.dart';
import '../utils/fireStoreServices.dart';
class TaskCard extends StatelessWidget {
const TaskCard({super.key});
@override
Widget build(BuildContext context) {
Color getColor(Set<MaterialState> states) {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.white;
}
return Colors.yellow.shade900;
}
final TodosDatabaeServices _todosDatabaseServices = TodosDatabaeServices();
final CollectionReference<Map<String, dynamic>> _collectionReference =
FirebaseFirestore.instance.collection('todos');
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final _fireStore = FirebaseFirestore.instance;
final provider = Provider.of<stateServices>(context);
provider.isload(true,"${_firebaseAuth.currentUser?.uid}");
return Expanded(
child:StreamBuilder<QuerySnapshot>(
stream: _fireStore.collection("todos").where("id",isEqualTo:userId).snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot>
snapshot) {
List todos = snapshot.data?.docs??[];
if(todos.isEmpty){
print(todos.length);
return Text(todos.isNotEmpty?"Loading...":"No Todos please Add todos..",style:textStyle(16, Colors.grey.shade800, FontWeight.w600));
}
return todos.isNotEmpty?ListView.builder(
itemCount: todos.length,
itemBuilder:(context,index){
Map<String, dynamic> todosAll = todos[index].data();
String todosId = todos[index].id;
return Container(
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: secondaryColor,
),
margin: EdgeInsets.only(bottom: 10),
padding: EdgeInsets.all(5),
child: InkWell(
onLongPress: (){
_todosDatabaseServices.deleteTodos(todosId);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(todosAll['task'],style: textStyle(18, Colors.grey.shade800, FontWeight.bold),),
SizedBox(height: 4,),
Text(DateFormat("dd-MM-yy h:mm a")
.format(todosAll['createOn'].toDate())),
],
) ,
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Checkbox(
fillColor: MaterialStateProperty.resolveWith(getColor),
checkColor: Colors.white,
value: todosAll['isDone'],
onChanged: (bool? value) async{
try {
await _collectionReference.doc(todosId).update({
'isDone': !todosAll['isDone'],
'updateOn': Timestamp.now(),
// Update other fields as needed
});
print('Data updated successfully for document with ID: $todosId');
} catch (e) {
print('Error updating data');
}
},
)
],
),
],
),
),
);
}
):CircularProgressIndicator(
color: primaryColor,
);
}),
);
}
}
import 'package:intl/intl.dart';
import 'package:toodos/modals/todos.dart';
import '../export/export.dart';
import '../utils/fireStoreServices.dart';
class TaskCard extends StatelessWidget {
const TaskCard({super.key});
@override
Widget build(BuildContext context) {
Color getColor(Set<MaterialState> states) {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.white;
}
return Colors.yellow.shade900;
}
final TodosDatabaeServices _todosDatabaseServices = TodosDatabaeServices();
final CollectionReference<Map<String, dynamic>> _collectionReference =
FirebaseFirestore.instance.collection('todos');
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final _fireStore = FirebaseFirestore.instance;
final provider = Provider.of<stateServices>(context);
provider.isload(true,"${_firebaseAuth.currentUser?.uid}");
return Expanded(
child:StreamBuilder<QuerySnapshot>(
stream: _fireStore.collection("todos").where("id",isEqualTo:userId).snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot>
snapshot) {
List todos = snapshot.data?.docs??[];
if(todos.isEmpty){
print(todos.length);
return Text(todos.isNotEmpty?"Loading...":"No Todos please Add todos..",style:textStyle(16, Colors.grey.shade800, FontWeight.w600));
}
return todos.isNotEmpty?ListView.builder(
itemCount: todos.length,
itemBuilder:(context,index){
Map<String, dynamic> todosAll = todos[index].data();
String todosId = todos[index].id;
return Container(
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: secondaryColor,
),
margin: EdgeInsets.only(bottom: 10),
padding: EdgeInsets.all(5),
child: InkWell(
onLongPress: (){
_todosDatabaseServices.deleteTodos(todosId);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(todosAll['task'],style: textStyle(18, Colors.grey.shade800, FontWeight.bold),),
SizedBox(height: 4,),
Text(DateFormat("dd-MM-yy h:mm a")
.format(todosAll['createOn'].toDate())),
],
) ,
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Checkbox(
fillColor: MaterialStateProperty.resolveWith(getColor),
checkColor: Colors.white,
value: todosAll['isDone'],
onChanged: (bool? value) async{
try {
await _collectionReference.doc(todosId).update({
'isDone': !todosAll['isDone'],
'updateOn': Timestamp.now(),
// Update other fields as needed
});
print('Data updated successfully for document with ID: $todosId');
} catch (e) {
print('Error updating data');
}
},
)
],
),
],
),
),
);
}
):CircularProgressIndicator(
color: primaryColor,
);
}),
);
}
}
- Get link
- X
- Other Apps
Comments
Post a Comment