在我的应用程序中,我有几个流。
这是来自appsflyer 的示例应用程序。我用它来深度链接我的应用程序。
https://pub.dev/packages/appsflyer_sdk
在第一页我们有;
return Scaffold(
appBar: AppBar(
title: Column(
children: <Widget>[
Text('AppsFlyer SDK example app'),
FutureBuilder<String>(
future: _appsflyerSdk.getSDKVersion(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return Text(snapshot.hasData ? snapshot.data : "");
})
],
),
),
body: FutureBuilder<dynamic>(
future: _appsflyerSdk.initSdk(
registerConversionDataCallback: true,
registerOnAppOpenAttributionCallback: true),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else {
if (snapshot.hasData) {
return HomeContainer(
onData:
_appsflyerSdk.conversionDataStream?.asBroadcastStream(),
onAttribution: _appsflyerSdk.appOpenAttributionStream
?.asBroadcastStream(),
trackEvent: logEvent,
);
} else {
return Center(child: Text("Error initializing sdk"));
}
}
}),
);
在 HomeContainer 中
Stream<Map> onData;
Stream<Map> onAttribution;
Future<bool> Function(String, Map) trackEvent;
HomeContainer({this.onData, this.onAttribution, this.trackEvent});
内部构建;
Column(
children: <Widget>[
StreamBuilder<dynamic>(
stream: widget.onData,
builder:
(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return TextBorder(
controller: TextEditingController(
text: snapshot.hasData
? Utils.formatJson(snapshot.data)
: "No conversion data"),
labelText: "Conversion Data:",
);
}),
Padding(
padding: EdgeInsets.only(top: 12.0),
),
StreamBuilder<dynamic>(
stream: widget.onAttribution,
builder:
(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return TextBorder(
controller: TextEditingController(
text: snapshot.hasData
? _processData(snapshot.data)
: "No attribution data"),
labelText: "Attribution Data:",
);
}),
],
),
我所做的是使用 notifyListeners 放置一个按钮来重新加载屏幕。
当我这样做时,我会收到以下错误;
Bad state: Stream has already been listened to.
我认为,问题可能是由于我重新加载页面时这些流仍然打开。
但我不知道如何关闭它们。
任何人都可以提供一些帮助吗?