how to make drop down in flutter using split for removing comma on column value of sqflite database

孤街浪徒 提交于 2020-01-25 08:56:04

问题


i want dropdown of stages in flutter which values come from sqflite database. the sample value in json is in below format and these values are store locally. there are two dropdown

if i select 'teacher' pipeline then it's id 54 was passed to future builder of stages's dropdown and i want to select one stage.

         {
            "id": 54,
            "name": "teacher",
            "stages": "{\"advertise\":false,\"interview\":false}",
            "created_at": "2019-08-23 20:11:54",
            "updated_at": "2019-08-23 20:12:48",
            "deleted_at": null
        },

the below is future builder for dropdown

                             FutureBuilder(
                              future: pipelineHelper.getPipeStage(pipelineId),
                              builder: (BuildContext context,
                                  AsyncSnapshot<List<Pipeline>>
                                  snapshot) {
                                if (!snapshot.hasData)
                                  return CircularProgressIndicator();
                                return DropdownButton(
                                  items: snapshot.data
                                      .map((stageList) => DropdownMenuItem<Pipeline>(
                                    value: stageList, child: Text(stageList.stages),))
                                      .toList(),
                                  onChanged: (value) {
                                    setState(() {
                                      stageName = value.stages;
                                      debugPrint('stage selected');
                                    });
                                  },
                                  isExpanded: true,
                                  hint: Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      SizedBox(height: 8.0),
                                      Text('Stage',style: _fontSize,),
                                      stageName == null ? Text('') : Text(stageName,style: _blackColor)
                                    ],),
                                );
                              }),

when i try

 items: snapshot.data.stages.split(',')

i got Error: The getter 'stages' isn't defined for the class 'List' error. The below is my helper function

Future<List<Pipeline>> getPipeStage(int number) async {
Database db = await this.database;
var orgMapList = await db.rawQuery('SELECT $colStages from $pipeTable WHERE $colId = $number'); // Get 'Map List' from database
int count = orgMapList.length;
 List<Pipeline> pipeList = List<Pipeline>();
// For loop to create a 'Pipeline List' from a 'Map List'
for (int i = 0; i < count; i++) {
  pipeList.add(Pipeline.fromMapObject(orgMapList[i]));
}
return pipeList;

}

来源:https://stackoverflow.com/questions/58056814/how-to-make-drop-down-in-flutter-using-split-for-removing-comma-on-column-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!