我找不到在ListviewBuilder中使用AppBar的方法。以下是代碼(這段代碼不能正常作業,只得到白色的螢屏)
Widget build(BuildContext context) {
return FutureBuilder<Categories> (
未來。_futureCategories,
建設者。(BuildContext context, AsyncSnapshot<Categories> snapshot) {
if (snapshot.hasData) {
final name = snapshot.data?
return DefaultTabController(
長度。2,
孩子。Scaffold(
body: ListView.builder(
itemCount: name?.length,
itemBuilder。(BuildContext context, int index) {
return AppBar(
標題。const Text('Hello')。
底部。TabBar(
標簽。[
Text(' ${name?[index].name}'.toUpperCase())。
Text(' ${name?[index].name}'.toUpperCase() ),
],
isScrollable。true,
labelColor: Colors.black,
),
);
},
),
),
);
} else if (snapshot.hasError) {
return NewsError(
errorMessage: '${snapshot.hasError}'/span>。
);
為什么我必須在Listview中使用AppBar?因為我必須為TabBarController使用索引值。
有什么辦法可以做到這一點嗎?
uj5u.com熱心網友回復:
根據你的代碼,你想實作的不是一個好的用戶體驗和界面。(有一個帶有多個appbar的Listview)。最好是用FutureBuilder包裝你的ListView,你能提供一個你想要的解決方案的截圖嗎?
uj5u.com熱心網友回復:
你得到白屏的原因是加載狀態
使用FutureBuilder如
FutureBuilder(
構建者。(context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return Center(
孩子。CircularProgressIndicator(),
);
else if (snapshot.hasData) return DefaultTabController...你的資料 Widget....。
return Text(snapshot.error.toString())。
},
),
你可以在Scaffold上找到appBar。
但如果你仍然希望在ListView.builder上有appBar,請嘗試
itemCount: name?.length 1,
itemBuilder。(context, index) {
return index == 0 ? AppBar() : Text("index $index")。
},
如果你沒有任何理由,我建議從構建方法中回傳支架,而不是FutureBuilder。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/313105.html
標籤:
上一篇:如何通過錯誤資訊找到屬性的id
下一篇:按問題型別的Dart修復
