Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Future<List<List<Widget>>> getList(List<int> list, String column) async {
  2. List<Widget> list1 = List();
  3. List<Widget> list2 = List();
  4. List<Widget> list3 = List();
  5. List<List<Widget>> listFromDB = [list1, list2, list3];
  6. var databasesPath = await getDatabasesPath();
  7. String path = join(databasesPath, 'books.db');
  8. Database database = await openDatabase(path, version: 1);
  9. for (int i = 0; i < list.length; i++) {
  10. var result = await database
  11. .rawQuery('SELECT DISTINCT $column FROM $booksTable WHERE $colId= ${list[i]}');
  12.  
  13. debugPrint('List: ' +list[i].toString());
  14. if (list[i] < 18) list1.add(_item(result[0][column].toString()));
  15. if (list[i] > 17 && list[i] < 50)
  16. list2.add(_item(result[0][column].toString()));
  17. if (list[i] > 49) list3.add(_item(result[0][column].toString()));
  18. }
  19.  
  20. // await database.close();
  21. return listFromDB;
  22. }
  23.  
  24. bool _summary = false;
  25.  
  26. _getAnswer() async{
  27. SharedPreferences pref = await SharedPreferences.getInstance();
  28. List<String> listString = pref.getStringList('Answers') ?? List();
  29.  
  30. if(listString.isNotEmpty){
  31. List<int> listInt = listString.map(int.parse).toList();
  32. listInt.sort();
  33. _list = await DB().getList(listInt, _summary ? 'Detail' : 'Output'); //colums from db.
  34.  
  35. setState((){});
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement