我有一個ListView在另一個ListView里面,如果我把它單獨放進去,兩個ListView都能正確顯示值,但是當我把它放在另一個ListView的itemBuilder里面時,我得到了Null check operator cannot be used on a null value error。我不確定我在這里做錯了什么。
以下是我的代碼 -
List<String> contactsGroup = [
'Contacts 1',
'Contacts 2',
];
小工具_showModalBottomSheet(contactsGroup, totalContacts) =>
DraggableScrollableSheet(
initialChildSize: 0.7,
maxChildSize: 0.9,
建設者。(_, controller) => Container(
裝飾。BoxDecoration(
color: Colors.white,
borderRadius: borderRadius.vertical(top: Radius.round(10))。
padding: EdgeInsets.all(10)。
孩子。ListView.separated(
itemBuilder: (context, x) => Padding(
padding: EdgeInsets.all(8.0)。
孩子。Align(
對齊。Alignment.centerLeft,
孩子。列(
兒童。[
Text(contactsGroup[x]),
ListView.builder(
itemBuilder: (context, y) => Padding(
padding: EdgeInsets.all(8.0)。
孩子。Align(
對齊。Alignment.centerLeft,
孩子。列(
兒童。[
Text(contactsList[y].displayName)。
],
),
),
),
itemCount: contactsList.length,
),
],
),
),
),
SeparatorBuilder: (context, index) => Divider(
color: Colors.black,
),
itemCount: contactsGroup.length,
),
),
);
下面是對上述方法的呼叫 -
onTap: () async {
await contactsBottomSheet.fetchContacts()。
contactsList = (contactsBottomSheet.phoneContactsOnBol
contactsBottomSheet.phoneContactsNotOnBol)。)
int totalContacts = contactsList.length;
List<String> contactsGroup = [
'Contacts on Bol',
'不在Bol上的聯系人'.
];
//contactsList.sort((a, b) => ["displayName"].compareTo(b["displayName"]));/span>
showModalBottomSheet(
isScrollControlled: true,
isDismissible: true,
backgroundColor: Colors.transparent,
context: 背景關系。
builder: (context) => _showModalBottomSheet(
contactsGroup, totalContacts)。)
);
},
uj5u.com熱心網友回復:
問題是嵌套的ListView,而內部采取了無限的大小,如果你用SizedBox(height: x)來包裝它,就可以解決這個問題。但根據談話內容,你不希望它是可滾動的,所以我把它們加在列上,并洗掉了內部的Listview.
Demo Widget我使用了假的資料進行測驗,希望你能理解。
。
小工具_showModalBottomSheet(int contactsGroup, int totalContacts) =>
DraggableScrollableSheet(
initialChildSize: 0.7,
maxChildSize: 0.9,
建設者。(_, controller) => Container(
裝飾。BoxDecoration(
color: Colors.white,
borderRadius: borderRadius.vertical(top: Radius.round(10))。
padding: EdgeInsets.all(10)。
孩子。ListView.separated(
itemBuilder: (context, x) => Padding(
padding: EdgeInsets.all(8.0)。
孩子。Align(
對齊。Alignment.centerLeft,
孩子。列(
兒童。[
Text("Contact")。
...List.generation(
4,
(index) => Padding(
padding: EdgeInsets.all(8.0)。
孩子。Align(
對齊。Alignment.centerLeft,
孩子。列(
兒童。[
Text("data here"),
],
),
),
),
)
],
)),
),
separatorBuilder。(context, index) => Divider(
color: Colors.black,
),
itemCount: contactsGroup,
),
),
);
如果它解決了你的問題,請告訴我
。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315687.html
標籤:
上一篇:小部件的生命周期問題

