You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
240 lines
8.1 KiB
Dart
240 lines
8.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:tangheem/api/tangheem_user_api_client.dart';
|
|
import 'package:tangheem/classes/colors.dart';
|
|
import 'package:tangheem/classes/utils.dart';
|
|
import 'package:tangheem/models/aya_model.dart';
|
|
import 'package:tangheem/models/surah_model.dart';
|
|
import 'package:tangheem/widgets/aya_player_widget.dart';
|
|
import 'package:tangheem/widgets/common_dropdown_button.dart';
|
|
|
|
class SurahScreen extends StatefulWidget {
|
|
static const String routeName = "/surah";
|
|
final String query;
|
|
|
|
SurahScreen({Key key, @required this.query}) : super(key: key);
|
|
|
|
@override
|
|
_SurahScreenState createState() {
|
|
return _SurahScreenState();
|
|
}
|
|
}
|
|
|
|
class _SurahScreenState extends State<SurahScreen> {
|
|
int _selectedSurah = 0;
|
|
int _selectedFromAya = 0;
|
|
int _selectedToAya = 0;
|
|
|
|
int _currentPage = 0;
|
|
int _ayaInPage = 0;
|
|
List<String> _surahList = [];
|
|
List<int> _fromAyaList = [];
|
|
List<int> _toAyaList = [];
|
|
|
|
SurahModel _surahModel;
|
|
AyaModel _ayaModel;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getSurahAndAya();
|
|
}
|
|
|
|
void getSurahAndAya() async {
|
|
Utils.showLoading(context);
|
|
try {
|
|
_surahModel = await TangheemUserApiClient().getSurahs();
|
|
_surahList = _surahModel.data.map((element) => element.nameEN).toList();
|
|
filterData();
|
|
} catch (ex, tr) {
|
|
Utils.handleException(ex, null);
|
|
} finally {
|
|
Utils.hideLoading(context);
|
|
}
|
|
}
|
|
|
|
int numberOfAyah = 0;
|
|
void filterData() {
|
|
numberOfAyah = _surahModel?.data[_selectedSurah]?.numberOfAyahs ?? 0;
|
|
var filteredAyahList = List.generate(getNextMultiple(numberOfAyah), (index) => index + 1).toList().where((element) => element == 1 || (element % 5) == 0).toList() ?? [];
|
|
_fromAyaList = filteredAyahList.getRange(0, filteredAyahList.length - 1)?.toList() ?? [];
|
|
_toAyaList = filteredAyahList.getRange(1, filteredAyahList.length)?.toList() ?? [];
|
|
getAyaByRange();
|
|
}
|
|
|
|
void getAyaByRange() async {
|
|
Utils.showLoading(context);
|
|
try {
|
|
_ayaModel = await TangheemUserApiClient().getAyaByRange(5, 1, _selectedSurah + 1, _fromAyaList[_selectedFromAya], _toAyaList[_selectedToAya]);
|
|
setState(() {});
|
|
} catch (ex, tr) {
|
|
Utils.handleException(ex, null);
|
|
} finally {
|
|
Utils.hideLoading(context);
|
|
}
|
|
}
|
|
|
|
int getNextMultiple(int num) {
|
|
int multipleOf = 5;
|
|
int nextDiff = multipleOf - (num % multipleOf);
|
|
int total = num + nextDiff;
|
|
return total;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.fromLTRB(16, 24, 16, 0),
|
|
width: double.infinity,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"اقرأ القرآن الكريم",
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20, color: ColorConsts.primaryBlue, height: 1),
|
|
),
|
|
SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: CommonDropDownButton(_selectedSurah, list: _surahList, onSelect: (index) {
|
|
if (_selectedSurah != index) {
|
|
_selectedSurah = index;
|
|
_selectedToAya = 0;
|
|
_selectedFromAya = 0;
|
|
filterData();
|
|
}
|
|
}),
|
|
),
|
|
SizedBox(width: 4),
|
|
Expanded(
|
|
child: CommonDropDownButton(_selectedFromAya, list: _fromAyaList.map((e) => "من الاية" + " $e").toList(), onSelect: (index) {
|
|
if (_selectedFromAya != index) {
|
|
_selectedFromAya = index;
|
|
_selectedToAya = index;
|
|
filterData();
|
|
}
|
|
}),
|
|
),
|
|
SizedBox(width: 4),
|
|
Expanded(
|
|
child: CommonDropDownButton(_selectedToAya, list: _toAyaList.map((e) => "الى الاية" + " $e").toList(), onSelect: (index) {
|
|
if (_selectedToAya != index) {
|
|
_selectedToAya = index;
|
|
filterData();
|
|
}
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 16),
|
|
Expanded(
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: 4, bottom: 4),
|
|
padding: EdgeInsets.only(top: 16, bottom: 4, right: 16, left: 16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
nextOptionButton("assets/icons/prev.svg", "سورة الفاتحة", () {}),
|
|
previousOptionButton("assets/icons/next.svg", "سورة آل عمران", () {}),
|
|
],
|
|
),
|
|
Expanded(
|
|
child: ListView(
|
|
physics: BouncingScrollPhysics(),
|
|
padding: EdgeInsets.only(top: 16, bottom: 8),
|
|
children: [
|
|
Text(
|
|
"بسم الله الرحمن الرحيم",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20, color: ColorConsts.primaryBlue, height: 1),
|
|
),
|
|
SizedBox(height: 8),
|
|
Container(
|
|
padding: EdgeInsets.only(left: 4, right: 4),
|
|
child: Text(
|
|
_ayaModel?.data?.map((e) => e.ayahText)?.toList()?.reduce((value, element) => value + element) ?? "",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontFamily: "UthmanicHafs",
|
|
color: ColorConsts.primaryBlue,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 8),
|
|
Text(
|
|
"1 2 3 4 5 6 7 8 9",
|
|
style: TextStyle(fontSize: 16, color: ColorConsts.textHintGrey),
|
|
),
|
|
SizedBox(height: 4),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
nextOptionButton("assets/icons/prev_single.svg", "الآيات السابقة", () {}),
|
|
previousOptionButton("assets/icons/next_single.svg", "الآيات التالية", () {}),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
AyaPlayerWidget()
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget nextOptionButton(String icon, String text, VoidCallback onPressed) {
|
|
return InkWell(
|
|
onTap: onPressed,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SvgPicture.asset(icon, height: 12, width: 12),
|
|
SizedBox(width: 4),
|
|
Text(
|
|
text,
|
|
style: TextStyle(color: ColorConsts.textGrey),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget previousOptionButton(String icon, String text, VoidCallback onPressed) {
|
|
return InkWell(
|
|
onTap: onPressed,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
text,
|
|
style: TextStyle(color: ColorConsts.textGrey),
|
|
),
|
|
SizedBox(width: 4),
|
|
SvgPicture.asset(icon, height: 12, width: 12),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|