我想将一个无状态Widget的列表传递给Tasktile,并传递给扩展ChangeNotifier的Taskdata类。Taskdata也用作tasktile的第二个消费者参数。 我正在尝试制作生日/周年纪念提醒应用程序。并且还显示了在不同的mont中分隔的生日。所以我需要度过一个月。
import 'dart:collection';
import 'package:wishes_sent/constants.dart';
import 'package:flutter/material.dart';
import 'package:wishes_sent/data.dart';
import 'tiles.dart';
import 'package:wishes_sent/constants.dart';
import 'package:provider/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class TaskData extends ChangeNotifier {
List<Task> month = [];
TaskData(this.month);
UnmodifiableListView<Task> get tasks {
return UnmodifiableListView(month);
}
int get taskCount {
getData();
return month.length;
}
void update() {
notifyListeners();
}
void updateTask(Task task) {
task.toggleDone();
notifyListeners();
}
}
class TasksList extends StatelessWidget {
List<Task> month;
TasksList(this.month);// pass this month to taskdata.So i can have 12 different Task list for 12 months
@override
Widget build(BuildContext context) {
return Consumer<TaskData>(
builder: (context, taskData, child) {
return ListView.builder(
itemCount: Provider.of<TaskData>(context).taskCount,
itemBuilder: (context, index) {
final task = taskData.tasks[index];
return TaskTile(
update: () {
taskData.update();
},
fullName: task.fullName,
emailID: task.emailID,
phoneNo: task.phoneNo,
userEmail: task.userEmail,
message: task.message,
type: task.type,
dateE: task.dateE,
id: task.id,
isVisible: task.isVisible,
color: task.color,
showMore: () {
print("LA LA LA Land yo bay yo ");
taskData.getData();
},
deleteTile: () {
taskData.deleteTask(task);
},
);
},
);
},
);
}
}