Flutter 流生成器颤振未更新

Flutter 流生成器颤振未更新,flutter,stream-builder,Flutter,Stream Builder,在我的呼叫应用程序中,我正在从下面给定的sqlite db获取呼叫历史数据 List<HistoryRecord> historyRecords; void getData(String argv) async { queryRows = []; historyRecords=null; List<Map<String, dynamic>> ok = await DatabaseHelper.instance.getAllLogsByGroup(arg

在我的呼叫应用程序中,我正在从下面给定的sqlite db获取呼叫历史数据

List<HistoryRecord> historyRecords;
void getData(String argv) async {
queryRows = [];
historyRecords=null;
List<Map<String, dynamic>> ok =
    await DatabaseHelper.instance.getAllLogsByGroup(argv);
setState(() {
  queryRows = ok;
  historyRecords=List<HistoryRecord>.from(
      queryRows.map((row) => HistoryRecord.fromJson(row)));
});
我正在initState()和didChangeAppLifecycleState(AppLifecycleState状态)中调用getData() 分别起作用
但每当我进行调用并调用结束时,此页面将恢复,一个条目将添加到我的数据库中,但不会反映在我的streamBuilder中

您应该阅读
.asStream()
方法说明:

dart:async
创建包含此未来结果的[流]。
该流将生成包含此未来完成结果的单个数据或错误事件,然后它将以完成事件结束。
如果未来从未完成,则流将不会产生任何事件。

我该怎么做看看这个包我有个问题
StreamBuilder(
                  stream: historyRecords.asStream(),
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      return ListView.builder(
                        shrinkWrap: true,
                        itemCount: snapshot.data.length,
                        itemBuilder: (context, index) {
                          return snapshot.data[index].displayName != null
                              ? ListTile(
                                  onTap: () async {
                                    Position position = (await Geolocator
                                        .getCurrentPosition(
                                            desiredAccuracy:
                                                LocationAccuracy.high));
                                    var number = snapshot
                                        .data[index].callHistoryNumber;
                                    number = number.startsWith("+92")
                                        ? "0" + number.substring(3)
                                        : number;
                                    print("Number Is " + number);
                                    await platform
                                        .invokeMethod("callMazay", {
                                      "number": number,
                                      "lat": position.latitude.toString(),
                                      "long": position.longitude.toString()
                                    });
                                  },
                                  leading: Container(
                                      decoration: BoxDecoration(
                                          shape: BoxShape.circle,
                                          gradient: snapshot
                                                      .data[index].avatar ==
                                                  null
                                              ? LinearGradient(
                                                  colors: [
                                                      Colors.red,
                                                      Colors.black12
                                                    ],
                                                  begin:
                                                      Alignment.bottomLeft,
                                                  end: Alignment.topRight)
                                              : null),
                                      child: snapshot.data[index].avatar ==
                                              null
                                          ? CircleAvatar(
                                              backgroundImage: AssetImage(
                                                  'assets/images/user.png'),
                                            )
                                          : CircleAvatar(
                                          backgroundImage: AssetImage(
                                              'assets/images/user.png')
                                              /*bckgroundImage: MemoryImage(
                                                  snapshot.dataa[index].avatar,scale: 0.1),*/
                                            )),
                                  trailing: Padding(
                                    padding: const EdgeInsets.all(10.0),
                                    child: Builder(
                                      builder: (context) {
                                        if (snapshot.data[index]
                                                .callHistoryType ==
                                            'MISSED') {
                                          return Wrap(
                                            children: [
                                              Padding(
                                                padding: const EdgeInsets.only(bottom:8.0,right: 12.0),
                                                child: Icon(Icons.call_missed,
                                                    color: Colors.red),
                                              ),
                                              Padding(
                                                padding:
                                                    const EdgeInsets.only(
                                                        bottom: 8.0),
                                                child: Column(
                                                  children: [
                                                    Icon(Icons.info_outline,
                                                        color: Colors.red),
                                                  ],
                                                ),
                                              )
                                            ],
                                          );
                                        } else if (snapshot.data[index]
                                                .callHistoryType ==
                                            'RECEIVED') {
                                          /*Column(
                                            children: [
                                              Icon(Icons.info_outline,
                                                  color: Colors.red)
                                            ],
                                          );*/
                                          return Wrap(
                                            children: [
                                              Padding(
                                                padding: const EdgeInsets.only(bottom:8.0,right: 12.0),
                                                child: Icon(Icons.call_received,
                                                    color: Colors.green),
                                              ),
                                              Padding(
                                                padding:
                                                const EdgeInsets.only(
                                                    bottom: 8.0),
                                                child: Column(
                                                  children: [
                                                    Icon(Icons.info_outline,
                                                        color: Colors.red),
                                                  ],
                                                ),
                                              )
                                            ],
                                          );
                                        } else {
                                         /* return Column(
                                            children: [
                                              Icon(Icons.info_outline,
                                                  color: Colors.red)
                                            ],
                                          );*/
                                          return Wrap(
                                            children: [
                                              Padding(
                                                padding: const EdgeInsets.only(bottom:8.0,right: 12.0),
                                                child: Icon(Icons.call_made,
                                                    color: Colors.yellow.shade900),
                                              ),
                                              Padding(
                                                padding:
                                                const EdgeInsets.only(
                                                    bottom: 8.0),
                                                child: Column(
                                                  children: [
                                                    Icon(Icons.info_outline,
                                                        color: Colors.red),
                                                  ],
                                                ),
                                              )
                                            ],
                                          );
                                        }
                                      },
                                    ),
                                  ),
                                  title: snapshot.data[index].total_calls !=
                                              null &&
                                          snapshot.data[index]
                                                  .total_calls ==
                                              1
                                      ? Text(
                                      snapshot.data[index].displayName,
                                          style:TextStyle(
                                            color: snapshot.data[index].callHistoryType ==
                                                'MISSED'?Colors.red:Colors.black,
                                          ))
                                      : Text(snapshot
                                              .data[index].displayName +
                                          " ( " +
                                          snapshot.data[index].total_calls
                                              .toString() +
                                          " )",style:TextStyle(
                                  color: snapshot.data[index].callHistoryType ==
                                  'MISSED'?Colors.red:Colors.black,
                                  )),
                                  subtitle: Text(
                                    snapshot.data[index].callHistoryDatetime,
                                      style:TextStyle(
                                        color: snapshot.data[index].callHistoryType ==
                                            'MISSED'?Colors.red:Colors.black,
                                      )
                                  ),
                                )
                              : null;
                        },
                      );
                    } else {
                      return Center(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                SpinKitRing(
                                  color: Colors.red,
                                  size: 50.0,
                                ),
                                Text("Loading...")
                              ],
                            )
                          ],
                        ),
                      );
                    }
                  },
                ),