Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何更新Listview.builder中的单个项目[颤振]_Flutter_Listview_Dart - Fatal编程技术网

Flutter 如何更新Listview.builder中的单个项目[颤振]

Flutter 如何更新Listview.builder中的单个项目[颤振],flutter,listview,dart,Flutter,Listview,Dart,我的应用程序有一个标签栏(使用Listview.builder构建),在标签栏上进行搜索(在每个标签上进行搜索),我的问题是当用户在TextField search上按textInputAction时,如何更新所选标签上的内容?(知道TabBar(选项卡)、TabBarView(childern)和search是使用futurebuilder从RESTAPI动态获取数据的) 代码段: TextField( textInputAction: Text

我的应用程序有一个标签栏(使用Listview.builder构建),在标签栏上进行搜索(在每个标签上进行搜索),我的问题是当用户在TextField search上按textInputAction时,如何更新所选标签上的内容?(知道TabBar(选项卡)、TabBarView(childern)和search是使用futurebuilder从RESTAPI动态获取数据的)

代码段:

    TextField(
                    textInputAction: TextInputAction.go,
                    onSubmitted: (newValue) {
                      print('TextFormField text = $newValue');
                      getPermitsApi(
                          status: _tabController.index + 1,
                          search: searchController.text);
                    },



  Future<void> getPermitsApi({@required int status, String search}) async {
if (search == null) {
  search = '';
}
GetPermitsModel getPermitsModel = GetPermitsModel();
_selectedIndex = widget.index;
if (_selectedIndex == 2) {
  _selectedIndex--;
}
http.Response response = await http.get(
    '*******/getPermits/$status/$_selectedIndex/$search',
    headers: {
      "api_key": "******",
      "DeviceToken":
          "*******"
    });
if (response.statusCode == 200) {
  var data = response.body;
  print('getPermits response $data');

  var dataMap = jsonDecode(data);
  if (jsonDecode(data)['result']['status'] == 0) {
    getPermitsModel = GetPermitsModel.fromJson(dataMap);
    print('tabWidgets = ${_tabsWidgets.length}');
    if (search != '') {
      setState(() {
        _tabsWidgets[status - 1] = tabContent(true, getPermitsModel);
      });
      // _tabsWidgets.insert(status - 1, tabContent(true, getPermitsModel));
      print(_tabsWidgets[status - 1]);
    } else {
      _tabsWidgets.add(tabContent(true, getPermitsModel));
    }
  } else if (jsonDecode(data)['result']['status'] == 1) {
    setState(() {
      _tabsWidgets.add(tabContent(false));
    });
  } else {
    _showAlert(alertMessage: getPermitsModel.result.additionalinformation);
  }
} }


  Widget tabContent(bool showContent, [GetPermitsModel getPermits]) {
return showContent
    ? ListView.builder(
        shrinkWrap: true,
        padding: const EdgeInsets.all(8),
        itemCount: getPermits.data.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => PermitDetails(
                          permitId: getPermits.data[index].permitId,
                          guId: getPermits.data[index].permitGuid)));
            },
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.white,
                  boxShadow: [
                    new BoxShadow(
                      color: Color(0xFFC6C6C6),
                      blurRadius: 4,
                    ),
                  ],
                  borderRadius: BorderRadius.circular(8)),
              height: 200,
              child: Column(
                children: <Widget>[
                  Container(
                    child: Text(
                      getPermits.data[index].permitId,
                      style: TextStyle(
                          color: darkGreen,
                          fontWeight: FontWeight.bold,
                          fontSize: 30),
                    ),
                    margin: EdgeInsets.only(top: 10, bottom: 15),
                  ),
                  Row(
                    textDirection: TextDirection.rtl,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(right: 8, left: 40),
                        child: Text(
                          'المقاول ',
                          style: TextStyle(color: darkGrey, fontSize: 20),
                        ),
                      ),
                      Text(
                        getPermits.data[index].contractor,
                        style: TextStyle(color: lightGrey, fontSize: 15),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Row(
                    textDirection: TextDirection.rtl,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(right: 8, left: 40),
                        child: Text(
                          'الموقع ',
                          style: TextStyle(color: darkGrey, fontSize: 20),
                        ),
                      ),
                      Text(
                        getPermits.data[index].address,
                        style: TextStyle(color: lightGrey, fontSize: 15),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Row(
                    textDirection: TextDirection.rtl,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(right: 8, left: 40),
                        child: Text(
                          'الحالة ',
                          style: TextStyle(color: darkGrey, fontSize: 20),
                        ),
                      ),
                      Text(
                        getPermits.data[index].permitStatus,
                        style: TextStyle(color: lightGrey, fontSize: 15),
                      )
                    ],
                  )
                ],
              ),
            ),
          );
        })
    : Center(child: Text('لا يوجد تصاريح')); }
TextField(
textInputAction:textInputAction.go,
提交:(新值){
打印('TextFormField text=$newValue');
getPermitsApi(
状态:\ tabController.index+1,
搜索:searchController.text);
},
未来的getPermitsApi({@required int status,String search})异步{
如果(搜索==null){
搜索=“”;
}
GetPermitsModel GetPermitsModel=GetPermitsModel();
_selectedIndex=widget.index;
如果(_selectedIndex==2){
_选择索引--;
}
http.Response-Response=等待http.get(
“********/GetPermissions/$status/$\u selectedIndex/$search”,
标题:{
“api_键”:“*******”,
“DeviceToken”:
"*******"
});
如果(response.statusCode==200){
var数据=response.body;
打印('GetPermissions response$data');
var dataMap=jsonDecode(数据);
如果(jsonDecode(数据)['result']['status']==0){
getPermitsModel=getPermitsModel.fromJson(数据映射);
打印('tabWidgets=${u tabsWidgets.length}');
如果(搜索!=''){
设置状态(){
_tabsWidgets[status-1]=tabContent(true,getPermitsModel);
});
//_tabsWidgets.insert(状态-1,tabContent(true,getPermitsModel));
打印(_-tabswidges[status-1]);
}否则{
_add(tabContent(true,getPermitsModel));
}
}else if(jsonDecode(数据)['result']['status']==1){
设置状态(){
_tabsWidgets.add(tabContent(false));
});
}否则{
_showAlert(alertMessage:getPermitsModel.result.additionalinformation);
}
} }
小部件选项卡内容(bool showContent,[GetPermitsModel GetPermissions]){
返回showContent
?ListView.builder(
收缩膜:对,
填充:常量边集。全部(8),
itemCount:GetPermissions.data.length,
itemBuilder:(上下文,索引){
返回手势检测器(
onTap:(){
导航器。推(
上下文
材料路线(
生成器:(上下文)=>PermitDetails(
permitId:getPermissions.data[index].permitId,
guId:GetPermissions.data[index].permitGuid));
},
子:容器(
装饰:盒子装饰(
颜色:颜色,白色,
boxShadow:[
新盒影(
颜色:颜色(0xFFC6),
半径:4,
),
],
边界半径:边界半径。圆形(8)),
身高:200,
子:列(
儿童:[
容器(
子:文本(
GetPermissions.data[index].permitId,
样式:TextStyle(
颜色:深绿色,
fontWeight:fontWeight.bold,
尺寸:30),,
),
页边距:仅限边集(顶部:10,底部:15),
),
划船(
textDirection:textDirection.rtl,
儿童:[
容器(
页边距:仅限边集(右:8,左:40),
子:文本(
'المقاول ',
样式:TextStyle(颜色:暗灰色,字体大小:20),
),
),
正文(
GetPermissions.data[索引]。承包商,
样式:TextStyle(颜色:浅灰色,字体大小:15),
)
],
),
大小盒子(
身高:10,
),
划船(
textDirection:textDirection.rtl,
儿童:[
容器(
页边距:仅限边集(右:8,左:40),
子:文本(
'الموقع ',
样式:TextStyle(颜色:暗灰色,字体大小:20),
),
),
正文(
GetPermissions.data[index]。地址,
样式:TextStyle(颜色:浅灰色,字体大小:15),
)
],
),
大小盒子(
身高:10,
),
划船(
textDirection:textDirection.rtl,
儿童:[
容器(
页边距:仅限边集(右:8,左:40),
子:文本(
'الحالة ',
样式:TextStyle(颜色:暗灰色,字体大小:20),
),
),
正文(
GetPermissions.data[index].permitStatus,
样式:TextStyle(颜色:浅灰色,字体大小:15),
)
],
)
],
),
),
);
})
:居中(子项:文本)