search sayfasi :
`
import ‘package:flutter/material.dart’;
import ‘package:quran_app/data/models/allsurah.dart’;
import ‘package:quran_app/data/models/ayetler_model.dart’;
import ‘package:quran_app/data/models/surah_info.dart’;
import ‘package:quran_app/data/services.dart’;
class Search_Ayahs extends StatefulWidget {
Search_Ayahs({Key key}) : super(key: key);
@override
_Search_AyahsState createState() => _Search_AyahsState();
}
class _Search_AyahsState extends State<Search_Ayahs> {
List<Ayet> allAyet = new List();
List<Ayet> serachResultList = new List();
List<Ayet> viewSurahList = new List();
ServiceData serviceData;
getAyahs() async {
allAyet = await serviceData.loadAllAyet();
setState(() {});
}
@override
void initState() {
super.initState();
serviceData = ServiceData();
getAyahs(); // burada json i bir kez cektik
}
@override
Widget build(BuildContext context) {
return allAyet.isNotEmpty
? SingleChildScrollView(
child: Column(
children: [
Container(
margin:
EdgeInsets.only(top: 15, left: 22, right: 22, bottom: 5),
child: TextField(
decoration: InputDecoration(
suffixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(50),
),
hintText: 'Search ',
alignLabelWithHint: false,
// filled: true
),
onChanged: (text) {
if (text == '') {
} else {
serachResultList.clear();
allAyet.forEach((e) {
if (e.ayetDescription
.toLowerCase()
.contains(text.toLowerCase()))
serachResultList.add(e);
});
viewSurahList =
serachResultList; // arama bos degilse kelimeye alacak
}
setState(() {});
},
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
),
),
],
),
)
: CircularProgressIndicator();
}
}
`
service sayfasi
`
import ‘dart:convert’;
import ‘package:quran_app/data/models/allsurah.dart’;
import ‘package:quran_app/data/models/ayetler_model.dart’;
import ‘package:quran_app/data/models/surah_info.dart’;
import ‘package:flutter/services.dart’;
class ServiceData {
var infosurah = ‘surah/surah-info.json’;
Future<List<SurahInfo>> loadInfo() async {
var response = await rootBundle.loadString(infosurah);
Iterable data = json.decode(response);
return data.map((model) => SurahInfo.fromJson(model)).toList();
}
Future<AllSurah> loadSurah(int number) async {
final response = await rootBundle.loadString(‘surah/$number.json’);
var res = json.decode(response);
var data = res[‘$number’];
return AllSurah.fromJson(data);
}
Future<List<Ayet>> loadAllAyet() async {
List<Ayet> allAyet = List();
for (int i = 1; i <= 114; i++) {
AllSurah surah = await loadSurah(i);
allAyet.addAll(surah.translationsAyetler);
}
return allAyet;
}
}
`