SHARE
TWEET

Untitled

a guest Jun 26th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [
  2.   {
  3.     "key": "1",
  4.     "title": "Lesson 1",
  5.     "translations": [
  6.       {
  7.         "key": "de",
  8.         "text": "Übung 1"
  9.       },
  10.       {
  11.         "key": "pt-br",
  12.         "text": "Lição 1"
  13.       }
  14.     ],
  15.     "keywords": []
  16.   }
  17. ]
  18.      
  19. class LessonModel {
  20.   final String key;
  21.   final String title;
  22.   final List<LessonTranslationModel> translations;
  23.   final List<String> keywords;
  24.  
  25.   LessonModel({this.key, this.title, this.translations, this.keywords});
  26.  
  27.   factory LessonModel.fromJson(Map<String, dynamic> json) {
  28.     var translations = json['translations'] as List;
  29.     List<LessonTranslationModel> translationList = translations
  30.         .map<LessonTranslationModel>((translation) => LessonTranslationModel.fromJson(translation))
  31.         .toList();
  32.  
  33.     var keywords = json['keywords'] as List;
  34.     List<String> keywordList = List<String>.from(keywords);
  35.  
  36.     return LessonModel(
  37.       key: json['key'] as String,
  38.       title: json['title'] as String,
  39.       translations: translationList,
  40.       keywords: keywordList,
  41.     );
  42.   }
  43. }
  44.  
  45. class LessonTranslationModel {
  46.   final String key;
  47.   final String text;
  48.  
  49.   LessonTranslationModel({this.key, this.text});
  50.  
  51.   factory LessonTranslationModel.fromJson(Map<String, dynamic> json) {
  52.     return LessonTranslationModel(
  53.       key: json['key'] as String,
  54.       text: json['text'] as String,
  55.     );
  56.   }
  57. }
  58.      
  59. List<LessonModel> filteredLessons = response
  60.    .where((lesson) => lesson.title.contains(searchString) || lesson.keywords.contains(searchString))
  61.    .toList();
  62.      
  63. List<LessonModel> filteredLessons = response
  64.    .map((lesson) => lesson.translations
  65.       .where((translation) => translation.text == searchString)
  66.       .cast<LessonTranslationModel>()
  67.       .toList())
  68.    .cast<LessonModel>()    
  69.    .toList();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top