问题
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