我正在研究基本的支持票系统。我从Firebase(作为流或未来)那里获得门票。
我想允许一些过滤选项(例如按状态和类别进行排序)。
为此,我考虑使用未来的提供商获取列表和StatenotiferProvider,以根据使用哪种过滤器来更新列表。
这是我到目前为止的代码:
final ticketListStreamProvider =
RP.FutureProvider((_) => FirestoreService.getTicketList());
class TicketListNotifier extends RP.StateNotifier<List<Ticket>> {
TicketListNotifier() : super([]);
void addTicket(Ticket ticket) {
state = List.from(state)..add(ticket);
}
void removeTicket(Ticket ticket) {
state = List.from(state)..remove(ticket);
}
}
final ticketsController =
RP.StateNotifierProvider<TicketListNotifier, List<Ticket>>(
(ref) => TicketListNotifier(),
);
我有多个问题。首先它行不通。
Statenotifier接受列表,而不是未来&lt; list&gt;。我需要以某种方式将其转换或重写Statenotifier以接受未来。
我试图与一个官方例子之一保持联系。
()
不幸的是,他们没有使用来自firebase之类的外部来源的数据来执行此操作。
解决此问题的最佳方法是什么?
谢谢
I am working on a basic Support Ticket System. I get the Tickets from Firebase (Either as a Stream or Future).
I want to allow some Filtering Options (e.g. sort by Status and Category).
For this, I thought about using A Future Provider to get the List and a StateNotiferProvider to update the List depending on which filter is being used.
This is the code I have so far:
final ticketListStreamProvider =
RP.FutureProvider((_) => FirestoreService.getTicketList());
class TicketListNotifier extends RP.StateNotifier<List<Ticket>> {
TicketListNotifier() : super([]);
void addTicket(Ticket ticket) {
state = List.from(state)..add(ticket);
}
void removeTicket(Ticket ticket) {
state = List.from(state)..remove(ticket);
}
}
final ticketsController =
RP.StateNotifierProvider<TicketListNotifier, List<Ticket>>(
(ref) => TicketListNotifier(),
);
There are multiple issues I have with that. Firstly it doesn't work.
The StateNotifier accepts a List and not a Future<List>. I need to convert it somehow or rewrite the StateNotifier to accept the Future.
I was trying to stay close to one of the official examples.
(https://github.com/rrousselGit/riverpod/tree/master/examples/todos)
Unfortunately, they don't use data from an outside source like firebase to do it.
What's the best approach to get resolve this issue with which combination of providers?
Thanks
发布评论
评论(1)
ticketlistNotifier
中获取票务清单,并在您的票务列表中设置其状态。现在
ref.Read(ticketsController); < /code>将返回您的票务
TicketListNotifier
and set its state with your ticket list.Now
ref.read(ticketsController);
will return your ticket list