I am creating a Quran App which is having large data. I added all the data as in json format in the assets. But decoding it for some chapters taking so much time.
Any best method for optimizing the app. Below are the codes.
Future<String> getJson() { return rootBundle.loadString('assets/text_asset/quranex.json'); } List<QuranAyah> data; List<QuranAyah> quranAyahFromJson(String str) => List<QuranAyah>.from(json.decode(str).map((x) => QuranAyah.fromJson(x))); Future getData() async { data = quranAyahFromJson(await getJson()); print(data[0].aya); return data; }
below is the widget
FutureBuilder( future: getData(), builder: (context, snapshot) => snapshot.hasData ? ListView.builder( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemCount: data[widget.index].aya.length, itemBuilder: (context, index) { return AutoScrollTag( key: ValueKey(index), highlightColor: Colors.green.shade100, controller: controller, index: index, child: AyahWidget( surahMeaning: widget.titleMeaning, surahName: widget.title, surahIndex: widget.index + 1, ayah: data[widget.index].aya[index].text, index: data[widget.index].aya[index].index, meaning: _thafseer ? data[widget.index].aya[index].meaning : "", thafseer: _thafseer ? data[widget.index].aya[index].thafseer : "", ), ); }) : Center( child: CircularProgressIndicator(), ), ),
the json modal is below
class QuranAyah { QuranAyah({ this.index, this.name, this.surahmeaning, this.aya, }); String index; String name; String surahmeaning; List<Aya> aya; factory QuranAyah.fromJson(Map<String, dynamic> json) => QuranAyah( index: json["index"], name: json["name"], surahmeaning: json["surahmeaning"] == null ? null : json["surahmeaning"], aya: List<Aya>.from(json["aya"].map((x) => Aya.fromJson(x))), ); Map<String, dynamic> toJson() => { "index": index, "name": name, "surahmeaning": surahmeaning == null ? null : surahmeaning, "aya": List<dynamic>.from(aya.map((x) => x.toJson())), }; } class Aya { Aya({ this.index, this.text, this.meaning, this.thafseer, this.vibagam, this.vajanam, this.bismillah, }); String index; String text; String meaning; String thafseer; String vibagam; String vajanam; String bismillah; factory Aya.fromJson(Map<String, dynamic> json) => Aya( index: json["index"], text: json["text"], meaning: json["meaning"] == null ? null : json["meaning"], thafseer: json["thafseer"] == null ? null : json["thafseer"], vibagam: json["vibagam"] == null ? null : json["vibagam"], vajanam: json["vajanam"] == null ? null : json["vajanam"], bismillah: json["bismillah"] == null ? null : json["bismillah"], ); Map<String, dynamic> toJson() => { "index": index, "text": text, "meaning": meaning == null ? null : meaning, "thafseer": thafseer == null ? null : thafseer, "vibagam": vibagam == null ? null : vibagam, "vajanam": vajanam == null ? null : vajanam, "bismillah": bismillah == null ? null : bismillah, }; }
and finaly the json data is here -> https://jsonblob.com/08cc5da3-4339-11eb-85e7-1b58be500f91
https://stackoverflow.com/questions/65387082/how-to-parse-or-use-large-data-locally-inside-flutter-i-am-creating-a-quran-app December 21, 2020 at 11:04AM
没有评论:
发表评论