还有. view A_ 在那。当从到through的转换触发附加到 的函数时。如果我不在,我不需要工作view BАFutureBuilderview Аview BNavigator.Push()FutureBuilderview AFutureBuilderviewFuturebuilder
这是代码“视图A”(_StoriesState),当我转到B(StoriesPage)时,会调用getStories函数,该函数只能在A(_StoriesState)中调用
............
Future<dynamic> getStories(int items, List<int> pickerSelectedIndex) async {
try {
............
return stories;
} on HandshakeException catch (e) {
print("HE: " + e.toString());
getStories(items, pickerSelectedIndex);
} on SocketException catch (e) {
print("SE: " + e.toString());
getStories(items, pickerSelectedIndex);
} on Exception catch (e) {
print(e);
getStories(items, pickerSelectedIndex);
}
}
............
class _StoriesState extends State<Stories> {
Future<List<Story>> listViewData;
............
Future<List<Story>> getStoriesDataReady(
int items, List<int> pickerSelectedIndex) async {
List<Story> stories = await getStories(items, pickerSelectedIndex);
if (globals.filter.isEmpty) {
return stories;
} else {
............
return searchStories;
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: ............
builder: (BuildContext context, AsyncSnapshot snapshot) {
List<Widget> children;
if (snapshot.hasData) {
listViewData =
getStoriesDataReady(globals.items, pickerSelectedIndex);
return Scaffold(
body: FutureBuilder<List<Story>>(
future: listViewData,
builder: (BuildContext context,
AsyncSnapshot<List<Story>> snapshot) {
if (snapshot.hasData) {
............
child: FloatingSearchBar.builder(
............
itemCount: snapshot.data.length + 1,
itemBuilder:
(BuildContext context, int index) {
............
onTap: () {
............
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => StoryPage(............)),
).then((value) {
FocusScope.of(context).requestFocus(FocusNode());
});
}
............
}),
............
});
}
}
请告诉我如何实现这个?
1)将初始化移动
listViewData到initState以便在创建小部件时对其进行一次初始化:2)你有什么问题
snapshot(名字相同......)?答案基于提供的代码和信息。这可能无法解决问题,因为它可能在其他地方......