|
|
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:tangheem/api/tangheem_user_api_client.dart';
|
|
|
|
|
import 'package:tangheem/app_state/surah_app_state.dart';
|
|
|
|
|
import 'package:tangheem/classes/colors.dart';
|
|
|
|
|
import 'package:tangheem/classes/utils.dart';
|
|
|
|
|
import 'package:tangheem/models/aya_model.dart';
|
|
|
|
|
@ -18,10 +19,9 @@ import 'tangheem_detail_screen.dart';
|
|
|
|
|
|
|
|
|
|
class QuranScreen extends StatefulWidget {
|
|
|
|
|
static const String routeName = "/surah";
|
|
|
|
|
final SurahModel surahModel;
|
|
|
|
|
final String query;
|
|
|
|
|
|
|
|
|
|
QuranScreen({Key key, this.surahModel, @required this.query}) : super(key: key);
|
|
|
|
|
QuranScreen({Key key, @required this.query}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_QuranScreenState createState() {
|
|
|
|
|
@ -37,7 +37,7 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
|
|
|
|
|
int _currentSurahIndex = -1;
|
|
|
|
|
int _currentPage = 0;
|
|
|
|
|
int _ayaInPage = 5;
|
|
|
|
|
|
|
|
|
|
List<String> _surahList = [];
|
|
|
|
|
List<int> _fromAyaList = [];
|
|
|
|
|
List<int> _toAyaList = [];
|
|
|
|
|
@ -56,19 +56,20 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getSurah() async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
if (widget.surahModel == null) {
|
|
|
|
|
if (SurahAppState().getSurahModel == null) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
_surahModel = await TangheemUserApiClient().getSurahs();
|
|
|
|
|
SurahAppState().setSurahModel(_surahModel);
|
|
|
|
|
} else {
|
|
|
|
|
_surahModel = widget.surahModel;
|
|
|
|
|
_surahModel = SurahAppState().getSurahModel;
|
|
|
|
|
}
|
|
|
|
|
_surahList = _surahModel.data.map((element) => element.nameAR).toList();
|
|
|
|
|
|
|
|
|
|
_currentPage = 1;
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
//filterData();
|
|
|
|
|
} catch (ex, tr) {
|
|
|
|
|
Utils.handleException(ex, null);
|
|
|
|
|
} finally {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
@ -119,11 +120,11 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
// _currentPage = 603;
|
|
|
|
|
_ayaModel = await TangheemUserApiClient().getQuranByPageNo(_currentPage + 1);
|
|
|
|
|
_ayaModel = await TangheemUserApiClient().getQuranByPageNo(_currentPage);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
setState(() {});
|
|
|
|
|
} catch (ex, tr) {
|
|
|
|
|
Utils.handleException(ex, null);
|
|
|
|
|
} finally {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
}
|
|
|
|
|
scrollToId.animateTo("$_currentPage", duration: Duration(milliseconds: 300), curve: Curves.ease);
|
|
|
|
|
@ -161,21 +162,26 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _clearFilterAndRefreshData() {
|
|
|
|
|
_selectedSurah = -1;
|
|
|
|
|
_selectedFromAya = -1;
|
|
|
|
|
_selectedToAya = -1;
|
|
|
|
|
getQuranByPageNo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
var tempList = _ayaModel?.data?.map((e) => e.surahNameEN)?.toList()?.toSet()?.toList() ?? [];
|
|
|
|
|
|
|
|
|
|
var tempList = _ayaModel?.data?.map((e) => e.surahNameAR)?.toList()?.toSet()?.toList() ?? [];
|
|
|
|
|
String _surahName = "";
|
|
|
|
|
_surahName = tempList.isEmpty ? "" : tempList?.last ?? "";
|
|
|
|
|
int index = _surahList.indexWhere((element) => element == _surahName);
|
|
|
|
|
if (index != null) {
|
|
|
|
|
_currentSurahIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String _surahAya = "";
|
|
|
|
|
|
|
|
|
|
_ayaModel?.data?.forEach((element) {
|
|
|
|
|
var temp = element.numberInSurah == 1 ? getBismillahWithSurahName(element.surahNameEN, element.surahID != 1, _surahAya.length <= 1) + element.ayahText : element.ayahText;
|
|
|
|
|
var temp = element.numberInSurah == 1 ? getBismillahWithSurahName(element.surahNameAR, element.surahID != 1, _surahAya.length <= 1) + element.ayahText : element.ayahText;
|
|
|
|
|
_surahAya = _surahAya + temp;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -208,10 +214,6 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
if (_selectedFromAya != index) {
|
|
|
|
|
_selectedFromAya = index;
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
|
|
/// _selectedToAya = index;
|
|
|
|
|
// _currentPage = index;
|
|
|
|
|
// getAyaByRange();
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
@ -221,8 +223,6 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
if (_selectedToAya != index) {
|
|
|
|
|
_selectedToAya = index;
|
|
|
|
|
setState(() {});
|
|
|
|
|
// _currentPage = index;
|
|
|
|
|
// getAyaByRange();
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
@ -253,10 +253,7 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
(_selectedSurah == -1 || _selectedFromAya == -1 || _selectedToAya == -1)
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
_selectedSurah = -1;
|
|
|
|
|
_selectedFromAya = -1;
|
|
|
|
|
_selectedToAya = -1;
|
|
|
|
|
getQuranByPageNo();
|
|
|
|
|
_clearFilterAndRefreshData();
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -280,18 +277,18 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
_currentSurahIndex <= 0 ? "" : getNotNullValue(_surahList, _currentSurahIndex - 1),
|
|
|
|
|
_currentSurahIndex <= 0
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
// _selectedSurah = _selectedSurah - 1;
|
|
|
|
|
// filterData();
|
|
|
|
|
: (value) {
|
|
|
|
|
_currentPage = _surahModel?.data?.elementAt(_surahList.indexOf(value))?.startPageNo ?? _currentPage;
|
|
|
|
|
_clearFilterAndRefreshData();
|
|
|
|
|
}),
|
|
|
|
|
previousOptionButton(
|
|
|
|
|
"assets/icons/next.svg",
|
|
|
|
|
_currentSurahIndex >= (_surahList.isNotEmpty ? (_surahList.length - 1) : 0) ? "" : getNotNullValue(_surahList, _currentSurahIndex + 1),
|
|
|
|
|
_currentSurahIndex >= (_surahList.isNotEmpty ? (_surahList.length - 1) : 0)
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
// _selectedSurah = _selectedSurah + 1;
|
|
|
|
|
// filterData();
|
|
|
|
|
: (value) {
|
|
|
|
|
_currentPage = _surahModel?.data?.singleWhere((element) => element.nameAR == value)?.startPageNo ?? _currentPage;
|
|
|
|
|
_clearFilterAndRefreshData();
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -372,27 +369,21 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
children: [
|
|
|
|
|
nextOptionButton(
|
|
|
|
|
"assets/icons/prev_single.svg",
|
|
|
|
|
"الآيات السابقة",
|
|
|
|
|
_currentPage == 0
|
|
|
|
|
"الصفحة السابقة",
|
|
|
|
|
_currentPage <= 1
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
: (value) {
|
|
|
|
|
_currentPage = _currentPage - 1;
|
|
|
|
|
_selectedSurah = -1;
|
|
|
|
|
_selectedFromAya = -1;
|
|
|
|
|
_selectedToAya = -1;
|
|
|
|
|
getQuranByPageNo();
|
|
|
|
|
_clearFilterAndRefreshData();
|
|
|
|
|
}),
|
|
|
|
|
previousOptionButton(
|
|
|
|
|
"assets/icons/next_single.svg",
|
|
|
|
|
"الآيات التالية",
|
|
|
|
|
"الصفحة التالية",
|
|
|
|
|
_currentPage == 604
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
: (value) {
|
|
|
|
|
_currentPage = _currentPage + 1;
|
|
|
|
|
_selectedSurah = -1;
|
|
|
|
|
_selectedFromAya = -1;
|
|
|
|
|
_selectedToAya = -1;
|
|
|
|
|
getQuranByPageNo();
|
|
|
|
|
_clearFilterAndRefreshData();
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -436,9 +427,9 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget nextOptionButton(String icon, String text, VoidCallback onPressed) {
|
|
|
|
|
Widget nextOptionButton(String icon, String text, Function(String) onPressed) {
|
|
|
|
|
return InkWell(
|
|
|
|
|
onTap: onPressed,
|
|
|
|
|
onTap: () => onPressed(text),
|
|
|
|
|
child: onPressed == null
|
|
|
|
|
? SizedBox()
|
|
|
|
|
: Row(
|
|
|
|
|
@ -486,9 +477,9 @@ class _QuranScreenState extends State<QuranScreen> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget previousOptionButton(String icon, String text, VoidCallback onPressed) {
|
|
|
|
|
Widget previousOptionButton(String icon, String text, Function(String) onPressed) {
|
|
|
|
|
return InkWell(
|
|
|
|
|
onTap: onPressed,
|
|
|
|
|
onTap: () => onPressed(text),
|
|
|
|
|
child: onPressed == null
|
|
|
|
|
? SizedBox()
|
|
|
|
|
: Row(
|
|
|
|
|
|