From fed3e33f061a676010d0b49fa18559410bd7a079 Mon Sep 17 00:00:00 2001 From: Muhammed-Rahif Date: Fri, 29 Mar 2024 03:15:23 +0530 Subject: [PATCH] refactor: code --- lib/providers/quran_provider.dart | 2 -- lib/screens/chapter_screen.dart | 18 +++++++--------- lib/theme/theme.dart | 2 +- lib/widgets/custom_progress_indicator.dart | 25 ++++++++++++++++++++++ lib/widgets/list_chapters.dart | 3 ++- lib/widgets/quran_page.dart | 25 ++++++++++++++++------ pubspec.lock | 16 +++++++------- pubspec.yaml | 2 +- 8 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 lib/widgets/custom_progress_indicator.dart diff --git a/lib/providers/quran_provider.dart b/lib/providers/quran_provider.dart index 349ded7..684e330 100644 --- a/lib/providers/quran_provider.dart +++ b/lib/providers/quran_provider.dart @@ -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); } diff --git a/lib/screens/chapter_screen.dart b/lib/screens/chapter_screen.dart index 9d9229d..3e21aab 100644 --- a/lib/screens/chapter_screen.dart +++ b/lib/screens/chapter_screen.dart @@ -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({ @@ -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( @@ -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), ), ); diff --git a/lib/theme/theme.dart b/lib/theme/theme.dart index 8b31e07..089ae58 100644 --- a/lib/theme/theme.dart +++ b/lib/theme/theme.dart @@ -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( diff --git a/lib/widgets/custom_progress_indicator.dart b/lib/widgets/custom_progress_indicator.dart new file mode 100644 index 0000000..1913f65 --- /dev/null +++ b/lib/widgets/custom_progress_indicator.dart @@ -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), + ), + ); + } +} diff --git a/lib/widgets/list_chapters.dart b/lib/widgets/list_chapters.dart index ed52b4c..d513c8d 100644 --- a/lib/widgets/list_chapters.dart +++ b/lib/widgets/list_chapters.dart @@ -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'; @@ -31,7 +32,7 @@ class _ListChaptersState extends State { future: allChaptersFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); + return const CustomProgressIndicator(); } if (snapshot.hasError) { diff --git a/lib/widgets/quran_page.dart b/lib/widgets/quran_page.dart index 9f27722..e33e009 100644 --- a/lib/widgets/quran_page.dart +++ b/lib/widgets/quran_page.dart @@ -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 { @@ -27,7 +28,9 @@ class _QuranPageState extends State { 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) { @@ -43,12 +46,20 @@ class _QuranPageState extends State { } 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), diff --git a/pubspec.lock b/pubspec.lock index 8ea091a..e2843e7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index efc451a..f1372ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: