Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed-Rahif committed Mar 28, 2024
1 parent e29ce20 commit fed3e33
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 30 deletions.
2 changes: 0 additions & 2 deletions lib/providers/quran_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class QuranProvider {
if (cache == null) {
final response = await dio.get(requestUrl);

print(response.requestOptions.uri.toString());

if (response.statusCode != 200 || response.data == null) {
return Future.error(response.statusMessage ?? errMsg);
}
Expand Down
18 changes: 8 additions & 10 deletions lib/screens/chapter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:quran/classes/chapter.dart';
import 'package:quran/constants/app_contants.dart';
import 'package:quran/widgets/quran_page.dart';
import 'package:indexed_list_view/indexed_list_view.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

class ChapterScreen extends StatelessWidget {
const ChapterScreen({
Expand All @@ -16,16 +16,15 @@ class ChapterScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ItemScrollController itemScrollController = ItemScrollController();

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (AppConstants.breakpoint.isActive(context)) {
Navigator.of(context).popUntil((route) => route.isFirst);
}
});

final controller = IndexedScrollController(
initialIndex: chapter.pages.first - 1,
keepScrollOffset: false,
);
itemScrollController.jumpTo(index: chapter.pages.first - 1);
});

return Scaffold(
appBar: AppBar(
Expand All @@ -45,10 +44,9 @@ class ChapterScreen extends StatelessWidget {
)
: null,
),
body: IndexedListView.builder(
controller: controller,
maxItemCount: 604,
minItemCount: 0,
body: ScrollablePositionedList.builder(
itemScrollController: itemScrollController,
itemCount: 604,
itemBuilder: (context, indx) => QuranPage(pageNo: indx + 1),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppTheme {
(states) => AppColors.primaryColor.withOpacity(.8));

return ThemeData(
textTheme: GoogleFonts.ubuntuTextTheme(),
fontFamily: GoogleFonts.ubuntu().fontFamily,
splashFactory: NoSplash.splashFactory,
iconTheme: const IconThemeData(color: AppColors.backgroundColor),
appBarTheme: const AppBarTheme(
Expand Down
25 changes: 25 additions & 0 deletions lib/widgets/custom_progress_indicator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';

class CustomProgressIndicator extends StatelessWidget {
const CustomProgressIndicator({super.key, this.text});

final String? text;

@override
Widget build(BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: text != null
? Text(
text!,
style: const TextStyle(
color: Colors.white24,
fontSize: 10,
),
)
: const CircularProgressIndicator(strokeCap: StrokeCap.round),
),
);
}
}
3 changes: 2 additions & 1 deletion lib/widgets/list_chapters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:quran/classes/chapter.dart';
import 'package:quran/providers/chapters_provider.dart';
import 'package:quran/screens/chapter_screen.dart';
import 'package:quran/widgets/custom_progress_indicator.dart';
import 'package:quran/widgets/display_error.dart';
import 'package:quran/constants/app_contants.dart';

Expand Down Expand Up @@ -31,7 +32,7 @@ class _ListChaptersState extends State<ListChapters> {
future: allChaptersFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
return const CustomProgressIndicator();
}

if (snapshot.hasError) {
Expand Down
25 changes: 18 additions & 7 deletions lib/widgets/quran_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart';
import 'package:quran/classes/verse.dart';
import 'package:quran/providers/verses_provider.dart';
import 'package:quran/utils/number_util.dart';
import 'package:quran/widgets/custom_progress_indicator.dart';
import 'package:quran/widgets/display_error.dart';

class QuranPage extends StatefulWidget {
Expand All @@ -27,7 +28,9 @@ class _QuranPageState extends State<QuranPage> {
future: versesByPageFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
return CustomProgressIndicator(
text: 'Loading page ${widget.pageNo}...',
);
}

if (snapshot.hasError) {
Expand All @@ -43,12 +46,20 @@ class _QuranPageState extends State<QuranPage> {
}

final verses = snapshot.data!;
// final allWords = verses.expand((verse) => verse.words).toList();
final pageText = verses
.map((verse) =>
verse.textUthmani +
NumberUtil.getArabicNumber(verse.verseNumber, isAyahEnd: true))
.join('');

final pageText = verses.map((verse) {
String str = '';

if (verse.verseNumber == 1 && verse.pageNumber != 1) {
str +=
'\n ▐░░░░░░░░░░░░░▌ بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ ▐░░░░░░░░░░░░░▌\n';
}

str += verse.textUthmani +
NumberUtil.getArabicNumber(verse.verseNumber, isAyahEnd: true);

return str;
}).join('');

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16).copyWith(top: 10),
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.7"
indexed_list_view:
dependency: "direct main"
description:
name: indexed_list_view
sha256: "19c080b6505ad3283f9e199f53122d4779159da88a3f9322a2c682aeccae53e0"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -355,6 +347,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.7.4"
scrollable_positioned_list:
dependency: "direct main"
description:
name: scrollable_positioned_list
sha256: "1b54d5f1329a1e263269abc9e2543d90806131aa14fe7c6062a8054d57249287"
url: "https://pub.dev"
source: hosted
version: "0.3.8"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
path_provider: ^2.1.2
google_fonts: ^6.2.1
auto_size_text: ^3.0.0
indexed_list_view: ^3.0.2
scrollable_positioned_list: ^0.3.8

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit fed3e33

Please sign in to comment.