[text] tilere

Viewer

  1. import 'dart:collection';
  2. import 'dart:convert';
  3. import 'dart:math';
  4.  
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get_connect/http/src/utils/utils.dart';
  9. import 'package:gurbani_app/models/baani_lines_model.dart';
  10. import 'package:gurbani_app/models/calculated_items.dart';
  11. import 'package:gurbani_app/models/db_result.dart';
  12. import 'package:gurbani_app/models/history_item.dart';
  13. import 'package:gurbani_app/screens/settings.dart';
  14. import 'package:gurbani_app/services/nitnem_service.dart';
  15. import 'package:gurbani_app/services/reader.dart';
  16. import 'package:gurbani_app/utils/contexts.dart';
  17. import 'package:gurbani_app/utils/languages.dart';
  18. import 'package:gurbani_app/utils/spans.dart';
  19. import 'package:gurbani_app/utils/theme.dart';
  20. import 'package:gurbani_app/widgets/baani_view_widget.dart';
  21. import 'dart:math' as math;
  22.  
  23. import 'package:flip_widget/flip_widget.dart';
  24. import 'package:gurbani_app/widgets/calculated_view_widget.dart';
  25. import 'package:gurbani_app/widgets/constraints.dart';
  26. import 'package:gurbani_app/widgets/helper.dart';
  27. import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
  28. import 'package:shared_preferences/shared_preferences.dart';
  29. import 'package:wakelock_plus/wakelock_plus.dart';
  30.  
  31. //ToDo: This class has to be renamed because this won't be the homescreen
  32.  
  33. // Future<void> updateGurbaniLists() async {
  34. //   // print(_linesPerPage);
  35. //   currentAng = await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo, loadSourceLines: true, lines: _linesPerPage, bookNo: _bookNo);
  36. //   if(currentAng.baaniLines.isEmpty){
  37. //     _sourcePageNo = _sourcePageNo + 1;
  38. //     _previousChapterTotalPages.add(_pageNo > 1? _pageNo-1 :1);
  39. //     _pageNo = 1;
  40. //     currentAng = await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo, lines: _linesPerPage, bookNo: _bookNo);
  41. //   }
  42. //   nextAng = await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo + 1, lines: _linesPerPage, bookNo: _bookNo);
  43. //   previousAng = _sourcePageNo ==1 && _pageNo ==1 ? DBResult(baaniLines: List.empty(), count: 0) : _sourcePageNo >=1 && _pageNo ==1 ? _previousChapterTotalPages.isEmpty ? DBResult(baaniLines: List.empty(), count: 0) : await Reader.getAngs(sourcePageNo: _sourcePageNo - 1,pageNo: _previousChapterTotalPages.last, lines: _linesPerPage) : await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo - 1, lines: _linesPerPage);
  44. //   setState(() {});
  45. // }
  46.  
  47. class PageScreen extends StatefulWidget {
  48.   final int pageNo;
  49.   final int bookNo;
  50.   final bool isNitnem;
  51.   // final bool isEnglishTransliteration;
  52.   final int nitnemId;
  53.   final bool searchView;
  54.   final int searchedAng;
  55.   final String title;
  56.   final BaaniLineModel? searchedBaaniLine;
  57.  
  58.   const PageScreen(
  59.       {super.key,
  60.       required this.title,
  61.       this.pageNo = 1,
  62.       this.bookNo = 1,
  63.       // this.isEnglishTransliteration = false,
  64.       this.isNitnem = false,
  65.       this.searchView = false,
  66.       this.nitnemId = 1,
  67.       this.searchedAng = 100,
  68.       this.searchedBaaniLine});
  69.  
  70.   @override
  71.   State<PageScreen> createState() => _PageScreenState();
  72. }
  73.  
  74. const double _MinNumber = 0.008;
  75. double _clampMin(double v) {
  76.   if (v < _MinNumber && v > -_MinNumber) {
  77.     if (v >= 0) {
  78.       v = _MinNumber;
  79.     } else {
  80.       v = -_MinNumber;
  81.     }
  82.   }
  83.   return v;
  84. }
  85.  
  86. class _PageScreenState extends State<PageScreen> {
  87.   final GlobalKey<FlipWidgetState> _flipKey = GlobalKey();
  88.   final GlobalKey myPageKey = GlobalKey();
  89.   final TextEditingController _searchController = TextEditingController();
  90.  
  91.   DBResult currentAng =
  92.       DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  93.   DBResult previousAng =
  94.       DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  95.   DBResult nextAng =
  96.       DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  97.   DBResult searchedAng =
  98.       DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  99.   LinkedList<CalculatedItems> calculatedPages = LinkedList<CalculatedItems>();
  100.   LinkedList<HistoryItem> _history = LinkedList<HistoryItem>();
  101.   late SharedPreferences prefs;
  102.   bool _showEnglishTransliteration = false;
  103.   bool _showEnglishTranslation = false;
  104.   bool _showPunjabiTranslation = false;
  105.   bool _showPunjabiTeekaTranslation = false;
  106.   bool _showHindiTranslation = false;
  107.   bool _showHindiTeekaTranslation = false;
  108.   bool nightmodevalue = false;
  109.   bool _showFaridkotTeekaTranslation = false;
  110.   bool _loadSourceLines = true;
  111.   bool _isBookMarked = false;
  112.   bool _initialized = false;
  113.   bool _isbold = false;
  114.   bool isbold = false;
  115.   bool _searchviewm = false;
  116.   Languages _language = Languages.Gurmukhi;
  117.   int _loadedLines = 0;
  118.   int _linesPerProcess = 20;
  119.   double _extraBottomPadding = 0;
  120.   bool _isDragging = false;
  121.   bool _showSearch = false;
  122.   int maxvalueofBook1 = 1430;
  123.   int maxvalueofBook2 = 1428;
  124.   String errorMessage = '';
  125.   final ItemScrollController _itemScrollController = ItemScrollController();
  126.   final ItemPositionsListener _itemPositionListener =
  127.       ItemPositionsListener.create();
  128.  
  129.   //late Size size;
  130.  
  131.   Future<void> updateGurbaniLists() async {
  132.     currentAng = await Reader.getAngs(
  133.         sourcePageNo: _sourcePageNo,
  134.         pageNo: _pageNo,
  135.         loadSourceLines: _loadSourceLines,
  136.         lines: _linesPerPage,
  137.         bookNo: _bookNo);
  138.     if (currentAng.baaniLines.isEmpty) {
  139.       if (_loadSourceLines) {
  140.         currentAng =
  141.             DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  142.         nextAng = DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  143.         placeWidgetsToPage();
  144.         setState(() {});
  145.         _loadedLines = _linesPerProcess;
  146.         return;
  147.       }
  148.       _sourcePageNo = _sourcePageNo + 1;
  149.       _previousChapterTotalPages.add(_pageNo > 1 ? _pageNo - 1 : 1);
  150.       _pageNo = 1;
  151.       currentAng = await Reader.getAngs(
  152.           sourcePageNo: _sourcePageNo,
  153.           pageNo: _pageNo,
  154.           lines: _linesPerPage,
  155.           bookNo: _bookNo);
  156.       // placeWidgetsToPage();
  157.     } else {
  158.       if (_loadSourceLines) {
  159.         if (_loadedLines >= currentAng.count) {
  160.           return;
  161.         }
  162.         placeWidgetsToPage();
  163.         setState(() {});
  164.         _loadedLines += _linesPerProcess;
  165.         return;
  166.       }
  167.     }
  168.     if (_loadedLines >= currentAng.count) {
  169.       return;
  170.     }
  171.     placeWidgetsToPage();
  172.     nextAng = await Reader.getAngs(
  173.         sourcePageNo: _sourcePageNo,
  174.         pageNo: _pageNo + 1,
  175.         lines: _linesPerPage,
  176.         bookNo: _bookNo);
  177.     previousAng = _sourcePageNo == 1 && _pageNo == 1
  178.         ? DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0)
  179.         : _sourcePageNo >= 1 && _pageNo == 1
  180.             ? _previousChapterTotalPages.isEmpty
  181.                 ? DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0)
  182.                 : await Reader.getAngs(
  183.                     sourcePageNo: _sourcePageNo - 1,
  184.                     pageNo: _previousChapterTotalPages.last,
  185.                     lines: _linesPerPage)
  186.             : await Reader.getAngs(
  187.                 sourcePageNo: _sourcePageNo,
  188.                 pageNo: _pageNo - 1,
  189.                 lines: _linesPerPage);
  190.     setState(() {
  191.       // print("calcualated");
  192.       // print(calculatedPages.length);
  193.     });
  194.     _loadedLines += _linesPerProcess;
  195.   }
  196.  
  197.   double _getAppbarAndStatusBarHeight() {
  198.     if (!_initialized) {
  199.       return 0.0;
  200.     }
  201.     double h = AppBar().preferredSize.height +
  202.         MediaQuery.of(context).padding.top +
  203.         MediaQuery.of(context).padding.bottom +
  204.         _extraBottomPadding;
  205.     return h;
  206.   }
  207.  
  208.   placeWidgetsToPage() {
  209.     if (currentAng.baaniLines.isEmpty) {
  210.       calculatedPages.clear();
  211.       return;
  212.     }
  213.  
  214.     TextSpan angSpan = getSpan("Ang");
  215.     double height =
  216.         getTextHeight(span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  217.     double additionalHeight = 8.h;
  218.     height += additionalHeight;
  219.     CalculatedItems calculatedItems = CalculatedItems(
  220.         textSpans: List.empty(growable: true),
  221.         pageNo: 0,
  222.         totalPages: 0,
  223.         angNo: _sourcePageNo,
  224.         // angNo: _pageNo,
  225.         height: height);
  226.     if (_loadedLines != 0) {
  227.       calculatedItems = calculatedPages.last;
  228.       height = calculatedItems.height;
  229.       calculatedPages.last.unlink();
  230.     }
  231.     currentAng.baaniLines
  232.         .skip(_loadedLines)
  233.         .take(_linesPerProcess)
  234.         .forEach((element) {
  235.       if (_language == Languages.Both) {
  236.         if (element.gurmukhi.isNotEmpty) {
  237.           TextSpan span = getAsscciiSpan(element.gurmukhi,
  238.               style: baaniTextStyle(
  239.                 color: nightmodevalue ? blackColor : whiteColor,
  240.                 fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  241.               ));
  242.           if (height +
  243.                   _getAppbarAndStatusBarHeight() +
  244.                   getTextHeight(
  245.                       span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  246.               Contexts.size!.height) {
  247.             calculatedItems.pageNo += 1;
  248.             calculatedItems.totalPages += 1;
  249.             calculatedItems.height = height;
  250.             calculatedPages.add(calculatedItems);
  251.             semiUpdate();
  252.             height = getTextHeight(
  253.                 span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  254.             calculatedItems = CalculatedItems(
  255.                 textSpans: List.empty(growable: true),
  256.                 pageNo: calculatedItems.pageNo,
  257.                 totalPages: calculatedItems.totalPages,
  258.                 angNo: _sourcePageNo);
  259.             height += additionalHeight;
  260.             height += getTextHeight(
  261.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  262.             calculatedItems.textSpans.add(span);
  263.           } else {
  264.             TextSpan span = getAsscciiSpan(element.gurmukhi,
  265.                 style: baaniTextStyle(
  266.                   fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  267.                   color: nightmodevalue ? blackColor : whiteColor,
  268.                 ));
  269.             height += getTextHeight(
  270.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  271.             calculatedItems.textSpans.add(span);
  272.             height += additionalHeight;
  273.             printSizes(height);
  274.           }
  275.         }
  276.         if (element.hindiTransliteration != null &&
  277.             (element.hindiTransliteration ?? "").isNotEmpty) {
  278.           TextSpan span2 = getAsscciiSpan(element.hindiTransliteration,
  279.               style: baaniTextStyle(
  280.                 color: nightmodevalue ? kButtonColor : klightbrown,
  281.                 fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  282.               ));
  283.           if (height +
  284.                   _getAppbarAndStatusBarHeight() +
  285.                   getTextHeight(
  286.                       span: span2, maxWidth: Contexts.size!.width - 2 * 8.w) >
  287.               Contexts.size!.height) {
  288.             calculatedItems.pageNo += 1;
  289.             calculatedItems.totalPages += 1;
  290.             calculatedItems.height = height;
  291.             calculatedPages.add(calculatedItems);
  292.             semiUpdate();
  293.             height = getTextHeight(
  294.                 span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  295.             calculatedItems = CalculatedItems(
  296.                 textSpans: List.empty(growable: true),
  297.                 pageNo: calculatedItems.pageNo,
  298.                 totalPages: calculatedItems.totalPages,
  299.                 angNo: _sourcePageNo);
  300.             height += additionalHeight;
  301.             height += getTextHeight(
  302.                 span: span2, maxWidth: Contexts.size!.width - 2 * 8.w);
  303.             calculatedItems.textSpans.add(span2);
  304.           } else {
  305.             height += getTextHeight(
  306.                 span: span2, maxWidth: Contexts.size!.width - 2 * 8.w);
  307.             calculatedItems.textSpans.add(span2);
  308.             height += additionalHeight;
  309.             printSizes(height);
  310.           }
  311.         }
  312.       } else if (_language == Languages.Gurmukhi) {
  313.         if (element.gurmukhi.isNotEmpty) {
  314.           TextSpan span = getAsscciiSpan(element.gurmukhi,
  315.               style: baaniTextStyle(
  316.                   color: nightmodevalue ? blackColor : whiteColor,
  317.                   fontWeight: _isbold ? FontWeight.bold : FontWeight.normal));
  318.           if (height +
  319.                   _getAppbarAndStatusBarHeight() +
  320.                   getTextHeight(
  321.                       span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  322.               Contexts.size!.height) {
  323.             calculatedItems.pageNo += 1;
  324.             calculatedItems.totalPages += 1;
  325.             calculatedItems.height = height;
  326.             calculatedPages.add(calculatedItems);
  327.             semiUpdate();
  328.             height = getTextHeight(
  329.                 span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  330.             calculatedItems = CalculatedItems(
  331.                 textSpans: List.empty(growable: true),
  332.                 pageNo: calculatedItems.pageNo,
  333.                 totalPages: calculatedItems.totalPages,
  334.                 angNo: _sourcePageNo);
  335.             height += additionalHeight;
  336.             height += getTextHeight(
  337.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  338.             calculatedItems.textSpans.add(span);
  339.           } else {
  340.             height += getTextHeight(
  341.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  342.             calculatedItems.textSpans.add(span);
  343.             height += additionalHeight;
  344.             printSizes(height);
  345.           }
  346.         }
  347.       } else {
  348.         if (element.hindiTransliteration != null &&
  349.             (element.hindiTransliteration ?? "").isNotEmpty) {
  350.           TextSpan span = getAsscciiSpan(element.hindiTransliteration,
  351.               style: baaniTextStyle(
  352.                 color: nightmodevalue ? kButtonColor : whiteColor,
  353.                 fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  354.               ));
  355.           if (height +
  356.                   _getAppbarAndStatusBarHeight() +
  357.                   getTextHeight(
  358.                       span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  359.               Contexts.size!.height) {
  360.             calculatedItems.pageNo += 1;
  361.             calculatedItems.totalPages += 1;
  362.             calculatedItems.height = height;
  363.             calculatedPages.add(calculatedItems);
  364.             semiUpdate();
  365.             height = getTextHeight(
  366.                 span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  367.             calculatedItems = CalculatedItems(
  368.                 textSpans: List.empty(growable: true),
  369.                 pageNo: calculatedItems.pageNo,
  370.                 totalPages: calculatedItems.totalPages,
  371.                 angNo: _sourcePageNo);
  372.             height += additionalHeight;
  373.             height += getTextHeight(
  374.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  375.             calculatedItems.textSpans.add(span);
  376.           } else {
  377.             height += getTextHeight(
  378.                 span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  379.             calculatedItems.textSpans.add(span);
  380.             height += additionalHeight;
  381.             printSizes(height);
  382.           }
  383.         }
  384.       }
  385.       //english transliteration
  386.       if (_showEnglishTransliteration &&
  387.           element.englishTransliteration != null &&
  388.           (element.englishTransliteration ?? "").isNotEmpty) {
  389.         // print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  390.         // print(element.englishTransliteration);
  391.         // print(element.englishTransliteration?.replaceAll(RegExp(",|!|'|;"), ""));
  392.         TextSpan span = getSpan(
  393.             element.englishTransliteration?.replaceAll(RegExp(",|!|'|;"), ""),
  394.             style: baaniTextStyle(
  395.               color: nightmodevalue ? darkGreeenColor : kgoldyellowBackground,
  396.               fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  397.             ));
  398.         if (height +
  399.                 _getAppbarAndStatusBarHeight() +
  400.                 getTextHeight(
  401.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  402.             Contexts.size!.height) {
  403.           calculatedItems.pageNo += 1;
  404.           calculatedItems.totalPages += 1;
  405.           calculatedItems.height = height;
  406.           calculatedPages.add(calculatedItems);
  407.           semiUpdate();
  408.           height = getTextHeight(
  409.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  410.           calculatedItems = CalculatedItems(
  411.               textSpans: List.empty(growable: true),
  412.               pageNo: calculatedItems.pageNo,
  413.               totalPages: calculatedItems.totalPages,
  414.               angNo: _sourcePageNo);
  415.           height += additionalHeight;
  416.           height += getTextHeight(
  417.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  418.           calculatedItems.textSpans.add(span);
  419.         } else {
  420.           height += getTextHeight(
  421.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  422.           calculatedItems.textSpans.add(span);
  423.           height += additionalHeight;
  424.           printSizes(height);
  425.         }
  426.       }
  427.  
  428.       if (_showEnglishTranslation &&
  429.           element.translationEnglish != null &&
  430.           (element.translationEnglish ?? "").isNotEmpty) {
  431.         TextSpan span = getSpan(element.translationEnglish,
  432.             style: baaniTextStyle(
  433.               color: nightmodevalue ? purpleColor : whiteColor,
  434.               fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  435.             ));
  436.         if (height +
  437.                 _getAppbarAndStatusBarHeight() +
  438.                 getTextHeight(
  439.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  440.             Contexts.size!.height) {
  441.           calculatedItems.pageNo += 1;
  442.           calculatedItems.totalPages += 1;
  443.           calculatedItems.height = height;
  444.           calculatedPages.add(calculatedItems);
  445.           semiUpdate();
  446.           height = getTextHeight(
  447.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  448.           calculatedItems = CalculatedItems(
  449.               textSpans: List.empty(growable: true),
  450.               pageNo: calculatedItems.pageNo,
  451.               totalPages: calculatedItems.totalPages,
  452.               angNo: _sourcePageNo);
  453.           height += additionalHeight;
  454.           height += getTextHeight(
  455.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  456.           calculatedItems.textSpans.add(span);
  457.         } else {
  458.           height += getTextHeight(
  459.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  460.           calculatedItems.textSpans.add(span);
  461.           height += additionalHeight;
  462.           printSizes(height);
  463.         }
  464.       }
  465.  
  466.       if (_showPunjabiTranslation &&
  467.           element.translationPunjabi != null &&
  468.           (element.translationPunjabi ?? "").isNotEmpty) {
  469.         TextSpan span = getAsscciiSpan(element.translationPunjabi,
  470.             style: baaniTextStyle(
  471.                 color: nightmodevalue ? darkRedColor : klightgreen,
  472.                 fontWeight: _isbold ? FontWeight.bold : FontWeight.normal));
  473.         if (height +
  474.                 _getAppbarAndStatusBarHeight() +
  475.                 getTextHeight(
  476.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  477.             Contexts.size!.height) {
  478.           calculatedItems.pageNo += 1;
  479.           calculatedItems.totalPages += 1;
  480.           calculatedItems.height = height;
  481.           calculatedPages.add(calculatedItems);
  482.           semiUpdate();
  483.           height = getTextHeight(
  484.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  485.           calculatedItems = CalculatedItems(
  486.               textSpans: List.empty(growable: true),
  487.               pageNo: calculatedItems.pageNo,
  488.               totalPages: calculatedItems.totalPages,
  489.               angNo: _sourcePageNo);
  490.           height += additionalHeight;
  491.           height += getTextHeight(
  492.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  493.           calculatedItems.textSpans.add(span);
  494.         } else {
  495.           height += getTextHeight(
  496.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  497.           calculatedItems.textSpans.add(span);
  498.           height += additionalHeight;
  499.           printSizes(height);
  500.         }
  501.       }
  502.  
  503.       if (_showPunjabiTeekaTranslation &&
  504.           element.translationPunjabiTeeka != null &&
  505.           (element.translationPunjabiTeeka ?? "").isNotEmpty) {
  506.         TextSpan span = getAsscciiSpan(element.translationPunjabiTeeka,
  507.             style: baaniTextStyle(
  508.               color: nightmodevalue ? kFbColor : kPinkColor,
  509.               fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  510.             ));
  511.         if (height +
  512.                 _getAppbarAndStatusBarHeight() +
  513.                 getTextHeight(
  514.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  515.             Contexts.size!.height) {
  516.           calculatedItems.pageNo += 1;
  517.           calculatedItems.totalPages += 1;
  518.           calculatedItems.height = height;
  519.           calculatedPages.add(calculatedItems);
  520.           semiUpdate();
  521.           height = getTextHeight(
  522.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  523.           calculatedItems = CalculatedItems(
  524.               textSpans: List.empty(growable: true),
  525.               pageNo: calculatedItems.pageNo,
  526.               totalPages: calculatedItems.totalPages,
  527.               angNo: _sourcePageNo);
  528.           height += additionalHeight;
  529.           height += getTextHeight(
  530.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  531.           calculatedItems.textSpans.add(span);
  532.         } else {
  533.           height += getTextHeight(
  534.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  535.           calculatedItems.textSpans.add(span);
  536.           height += additionalHeight;
  537.           printSizes(height);
  538.         }
  539.       }
  540.  
  541.       if (_showFaridkotTeekaTranslation &&
  542.           element.translationFaridkotTeeka != null &&
  543.           (element.translationFaridkotTeeka ?? "").isNotEmpty) {
  544.         TextSpan span = getAsscciiSpan(element.translationFaridkotTeeka,
  545.             style: baaniTextStyle(
  546.               color: nightmodevalue ? MongiaColor : klightbluee,
  547.               fontWeight: _isbold ? FontWeight.bold : FontWeight.normal,
  548.             ));
  549.         if (height +
  550.                 _getAppbarAndStatusBarHeight() +
  551.                 getTextHeight(
  552.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  553.             Contexts.size!.height) {
  554.           calculatedItems.pageNo += 1;
  555.           calculatedItems.totalPages += 1;
  556.           calculatedItems.height = height;
  557.           calculatedPages.add(calculatedItems);
  558.           semiUpdate();
  559.           height = getTextHeight(
  560.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  561.           calculatedItems = CalculatedItems(
  562.               textSpans: List.empty(growable: true),
  563.               pageNo: calculatedItems.pageNo,
  564.               totalPages: calculatedItems.totalPages,
  565.               angNo: _sourcePageNo);
  566.           height += additionalHeight;
  567.           height += getTextHeight(
  568.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  569.           calculatedItems.textSpans.add(span);
  570.         } else {
  571.           height += getTextHeight(
  572.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  573.           calculatedItems.textSpans.add(span);
  574.           height += additionalHeight;
  575.           printSizes(height);
  576.         }
  577.       }
  578.  
  579.       if (_showHindiTranslation &&
  580.           element.translationHindi != null &&
  581.           (element.translationHindi ?? "").isNotEmpty) {
  582.         TextSpan span =
  583.             getAsscciiSpan(element.translationHindi, style: baaniTextStyle());
  584.         if (height +
  585.                 _getAppbarAndStatusBarHeight() +
  586.                 getTextHeight(
  587.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  588.             Contexts.size!.height) {
  589.           calculatedItems.pageNo += 1;
  590.           calculatedItems.totalPages += 1;
  591.           calculatedItems.height = height;
  592.           calculatedPages.add(calculatedItems);
  593.           semiUpdate();
  594.           height = getTextHeight(
  595.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  596.           calculatedItems = CalculatedItems(
  597.               textSpans: List.empty(growable: true),
  598.               pageNo: calculatedItems.pageNo,
  599.               totalPages: calculatedItems.totalPages,
  600.               angNo: _sourcePageNo);
  601.           height += additionalHeight;
  602.           height += getTextHeight(
  603.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  604.           calculatedItems.textSpans.add(span);
  605.         } else {
  606.           height += getTextHeight(
  607.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  608.           calculatedItems.textSpans.add(span);
  609.           height += additionalHeight;
  610.           printSizes(height);
  611.         }
  612.       }
  613.  
  614.       if (_showHindiTeekaTranslation &&
  615.           element.translationHindiTeeka != null &&
  616.           (element.translationHindiTeeka ?? "").isNotEmpty) {
  617.         TextSpan span = getAsscciiSpan(element.translationHindiTeeka,
  618.             style: baaniTextStyle());
  619.         if (height +
  620.                 _getAppbarAndStatusBarHeight() +
  621.                 getTextHeight(
  622.                     span: span, maxWidth: Contexts.size!.width - 2 * 8.w) >
  623.             Contexts.size!.height) {
  624.           calculatedItems.pageNo += 1;
  625.           calculatedItems.totalPages += 1;
  626.           calculatedItems.height = height;
  627.           calculatedPages.add(calculatedItems);
  628.           semiUpdate();
  629.           height = getTextHeight(
  630.               span: angSpan, maxWidth: Contexts.size!.width - 2 * 8.w);
  631.           calculatedItems = CalculatedItems(
  632.               textSpans: List.empty(growable: true),
  633.               pageNo: calculatedItems.pageNo,
  634.               totalPages: calculatedItems.totalPages,
  635.               angNo: _sourcePageNo);
  636.           height += additionalHeight;
  637.           height += getTextHeight(
  638.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  639.           calculatedItems.textSpans.add(span);
  640.         } else {
  641.           height += getTextHeight(
  642.               span: span, maxWidth: Contexts.size!.width - 2 * 8.w);
  643.           calculatedItems.textSpans.add(span);
  644.           height += additionalHeight;
  645.           printSizes(height);
  646.         }
  647.       }
  648.     });
  649.  
  650.     if (calculatedItems.textSpans.isNotEmpty) {
  651.       calculatedItems.height = height;
  652.       calculatedPages.add(calculatedItems);
  653.     }
  654.     //   change total pages of all calculated items to the length of calculated pages
  655.     int p = 0;
  656.     calculatedPages.forEach((element) {
  657.       element.pageNo = p + 1;
  658.       element.totalPages = calculatedPages.length;
  659.       p++;
  660.     });
  661.   }
  662.  
  663.   printSizes(height) {
  664.     // print("========== Sizes ===========");
  665.     // print(size.height);
  666.     // print(height + _getAppbarAndStatusBarHeight());
  667.   }
  668.  
  669.   Future<void> getSearchedAng() async {
  670.     setState(() {
  671.       _isLoading = true;
  672.     });
  673.  
  674.     searchedAng = await Reader.search(
  675.         searchType: 1,
  676.         searchText: widget.searchedAng.toString(),
  677.         shabadId: widget.searchedBaaniLine?.shabadId,
  678.         // angNo :
  679.         // angno : widget.searchedAng,
  680.         bookNo: widget.searchedBaaniLine == null
  681.             ? widget.bookNo
  682.             : widget.searchedBaaniLine!.orderId > 60555
  683.                 ? 2
  684.                 : 1);
  685.     setState(() {
  686.       _isLoading = false;
  687.     });
  688.   }
  689.  
  690.   Future<void> goToSearchPage() async {
  691.     setState(() {
  692.       _isLoading = true;
  693.     });
  694.     searchedAng = await Reader.search(
  695.         searchType: 1,
  696.         searchText: widget.searchedAng.toString(),
  697.         shabadId: widget.searchedBaaniLine?.shabadId,
  698.         // angno : widget.searchedAng,
  699.         bookNo: widget.searchedBaaniLine == null
  700.             ? widget.bookNo
  701.             : widget.searchedBaaniLine!.orderId > 60555
  702.                 ? 2
  703.                 : 1);
  704.     setState(() {
  705.       _isLoading = false;
  706.     });
  707.   }
  708.  
  709.   isBookmarked() async {
  710.     final prefs = SharedPreferences.getInstance();
  711.     final List<BaaniLineModel>? storedItems = await prefs.then((value) => value
  712.         .getStringList('myBookmarksList')
  713.         ?.map((e) => BaaniLineModel.fromJson(jsonDecode(e)))
  714.         .toList());
  715.     if (storedItems != null) {
  716.       if (storedItems.contains(widget.searchedBaaniLine)) {
  717.         _isBookMarked = true;
  718.       } else {
  719.         _isBookMarked = false;
  720.       }
  721.       return;
  722.     }
  723.     _isBookMarked = false;
  724.   }
  725.  
  726.   saveToBookmarks(BaaniLineModel baaniLine) async {
  727.     final List<BaaniLineModel>? storedItems = prefs
  728.         .getStringList('myBookmarksList')
  729.         ?.map((e) => BaaniLineModel.fromJson(jsonDecode(e)))
  730.         .toList();
  731.     if (storedItems != null) {
  732.       if (storedItems.contains(baaniLine)) {
  733.         storedItems.remove(baaniLine);
  734.         prefs.setStringList('myBookmarksList',
  735.             storedItems.map((e) => jsonEncode(e.toJson())).toList());
  736.         setState(() {
  737.           _isBookMarked = false;
  738.         });
  739.         ScaffoldMessenger.of(context).showSnackBar(
  740.           SnackBar(
  741.             content: const Text('Removed from bookmark'),
  742.             duration: const Duration(seconds: 2),
  743.             action: SnackBarAction(
  744.               label: 'Close',
  745.               onPressed: () {
  746.                 // Code to execute.
  747.               },
  748.             ),
  749.           ),
  750.         );
  751.         return;
  752.       }
  753.       storedItems.add(baaniLine);
  754.       prefs.setStringList('myBookmarksList',
  755.           storedItems.map((e) => jsonEncode(e.toJson())).toList());
  756.       // await isBookmarked();
  757.       setState(() {
  758.         _isBookMarked = true;
  759.       });
  760.       ScaffoldMessenger.of(context).showSnackBar(
  761.         SnackBar(
  762.           content: const Text('Bookmarked'),
  763.           duration: const Duration(seconds: 2),
  764.           action: SnackBarAction(
  765.             label: 'Close',
  766.             onPressed: () {
  767.               // Code to execute.
  768.             },
  769.           ),
  770.         ),
  771.       );
  772.     } else {
  773.       prefs.setStringList('myBookmarksList', [jsonEncode(baaniLine.toJson())]);
  774.       setState(() {
  775.         _isBookMarked = true;
  776.       });
  777.     }
  778.   }
  779.  
  780.   Future<void> updateNitnemLists() async {
  781.     // print(_linesPerPage);
  782.     print(currentAng.count);
  783.     // print("================================");
  784.     // DateTime t = DateTime.now();
  785.     if (currentAng.count == 0) {
  786.       setState(() {
  787.         _isLoading = true;
  788.       });
  789.       currentAng = await Reader.getNitnemAngs(nitnemId: _nitnemId);
  790.       // currentAng = NitnemService.getNitnemById(id: _nitnemId);
  791.       // placeWidgetsToPage();
  792.     }
  793.     if (currentAng.baaniLines.isEmpty) {
  794.       currentAng = DBResult(baaniLines: LinkedList<BaaniLineModel>(), count: 0);
  795.       placeWidgetsToPage();
  796.       setState(() {
  797.         _isLoading = false;
  798.       });
  799.       _loadedLines = 0;
  800.       return;
  801.     }
  802.     // print( DateTime.now().millisecondsSinceEpoch - t.millisecondsSinceEpoch);
  803.     if (_loadedLines >= currentAng.count) {
  804.       return;
  805.     }
  806.     placeWidgetsToPage();
  807.     // nextAng = await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo + 1, lines: _linesPerPage, bookNo: _bookNo);
  808.     // previousAng = _sourcePageNo ==1 && _pageNo ==1 ? DBResult(baaniLines: List.empty(), count: 0) : _sourcePageNo >=1 && _pageNo ==1 ? _previousChapterTotalPages.isEmpty ? DBResult(baaniLines: List.empty(), count: 0) : await Reader.getAngs(sourcePageNo: _sourcePageNo - 1,pageNo: _previousChapterTotalPages.last, lines: _linesPerPage) : await Reader.getAngs(sourcePageNo: _sourcePageNo,pageNo: _pageNo - 1, lines: _linesPerPage);
  809.     setState(() {
  810.       _isLoading = false;
  811.     });
  812.     _loadedLines += _linesPerProcess;
  813.     // if(_pageNo >1 && currentAng.baaniLines.length-1 < _linesPerPage*_pageNo){
  814.     //   // print("reducing page no");
  815.     //   // _pageNo -= 1;
  816.     //
  817.     //   // _sourcePageNo += 1;
  818.     //   // return;
  819.     // }
  820.   }
  821.  
  822.   int _pageNo = 1;
  823.   int _sourcePageNo = 1;
  824.   int _linesPerPage = 10;
  825.   int _bookNo = 1;
  826.   bool _isNitnem = false;
  827.   int _nitnemId = 1;
  828.   // bool _searchviewm = false;
  829.   bool _isLoading = false;
  830.   bool? isLeftToRight;
  831.   String? _title = '';
  832.   List<int> _previousChapterTotalPages = <int>[];
  833.  
  834.   Offset _oldPosition = Offset.zero;
  835.   @override
  836.   void initState() {
  837.     _sourcePageNo = widget.pageNo;
  838.     // _bookNo = widget.bookNo;
  839.  
  840.     _bookNo = widget.searchedBaaniLine == null
  841.         ? widget.bookNo
  842.         : widget.searchedBaaniLine!.orderId > 60555
  843.             ? 2
  844.             : 1;
  845.  
  846.     // _isbold = widget.
  847.     // _showEnglishTransliteration = widget.isEnglishTransliteration;
  848.     _isNitnem = widget.isNitnem;
  849.  
  850.     _nitnemId = widget.nitnemId;
  851.     _extraBottomPadding = 10.h;
  852.     _title = widget.title;
  853.     _searchController.clear();
  854.  
  855.     _searchviewm = widget.searchView;
  856.  
  857.     super.initState();
  858.     // postFrameCallback();
  859.     WidgetsBinding.instance.addPostFrameCallback((_) async {
  860.       // await Future.delayed(Duration(milliseconds: 300));
  861.       WakelockPlus.enable();
  862.       prefs = await SharedPreferences.getInstance();
  863.       _isbold = prefs.getBool("boldValue") ?? false;
  864.       isbold = prefs.getBool("boldValue") ?? false;
  865.       nightmodevalue = prefs.getBool("nightmodevalue") ?? false;
  866.       print("$_isbold");
  867.       _showEnglishTransliteration =
  868.           prefs.getBool('showEnglishTransliteration') ?? false;
  869.       _showEnglishTranslation = prefs.getBool('showEnglishTranslation') ?? true;
  870.       _showPunjabiTranslation = prefs.getBool('showPunjabiTranslation') ?? true;
  871.       _showPunjabiTeekaTranslation =
  872.           prefs.getBool('showPunjabiTeekaTranslation') ?? false;
  873.       _showHindiTranslation = prefs.getBool('showHindiTranslation') ?? false;
  874.       _showHindiTeekaTranslation =
  875.           prefs.getBool('showHindiTeekaTranslation') ?? false;
  876.       _showFaridkotTeekaTranslation =
  877.           prefs.getBool('showFaridkotTeekaTranslation') ?? false;
  878.       _language = Languages.values[prefs.getInt('language') ?? 0];
  879.       print('$_language');
  880.  
  881.       _initialized = true;
  882.       resetLinesPerPage();
  883.       isBookmarked();
  884.       if (widget.searchView) {
  885.         //
  886.         // searchedAng = _pageNo as DBResult;
  887.         //  widget.searchedBaaniLine!.sourcePage!;
  888.         //
  889.       }
  890.     });
  891.     // updateGurbaniLists(); //kro
  892.     // setState(() {
  893.  
  894.     // });
  895.   }
  896.  
  897.   @override
  898.   void dispose() {
  899.     WakelockPlus.disable();
  900.     super.dispose();
  901.   }
  902.  
  903.   semiUpdate() {
  904.     if (calculatedPages.length == 1) {
  905.       setState(() {});
  906.     }
  907.   }
  908.  
  909.   resetLinesPerPage() {
  910.     if (widget.searchView) {
  911.       getSearchedAng();
  912.       return;
  913.     }
  914.     int linesToShow = 0;
  915.     if (_language == Languages.Both) {
  916.       linesToShow = 2;
  917.     } else {
  918.       linesToShow = 1;
  919.     }
  920.     if (_bookNo == 1) {
  921.       if (_showEnglishTransliteration) {
  922.         linesToShow += 1;
  923.       }
  924.       if (_showEnglishTranslation) {
  925.         linesToShow += 1;
  926.       }
  927.       if (_showPunjabiTranslation) {
  928.         linesToShow += 1;
  929.       }
  930.       if (_showPunjabiTeekaTranslation) {
  931.         linesToShow += 1;
  932.       }
  933.       if (_showHindiTranslation) {
  934.         linesToShow += 1;
  935.       }
  936.       if (_showHindiTeekaTranslation) {
  937.         linesToShow += 1;
  938.       }
  939.       if (_showFaridkotTeekaTranslation) {
  940.         linesToShow += 1;
  941.       }
  942.     } else {
  943.       if (_showEnglishTransliteration) {
  944.         linesToShow += 1;
  945.       }
  946.       if (_showEnglishTranslation) {
  947.         linesToShow += 1;
  948.       }
  949.     }
  950.     _linesPerPage = (10 - linesToShow);
  951.     // _linesPerPage = _language == Languages.Both && _showEnglishTransliteration ? 6 : _language == Languages.Both && !_showEnglishTransliteration ? 7 : _showEnglishTransliteration ? 7 : 10;
  952.     if (_isNitnem) {
  953.       updateNitnemLists();
  954.     } else {
  955.       updateGurbaniLists();
  956.     }
  957.   }
  958.  
  959.   // double _lineHeight({required Text textWidget}) {
  960.   //   final textPainter = TextPainter(
  961.   //     text: textWidget.text!.textSpan,
  962.   //     textDirection: TextDirection.ltr,
  963.   //     maxLines: 999, // A large number to ensure we get an accurate estimate
  964.   //   );
  965.   //
  966.   //   textPainter.layout(maxWidth: widget.maxWidth);
  967.   //   textPainter.computeLineMetrics().length;
  968.   //   setState(() {
  969.   //   });
  970.   // }
  971.  
  972.   goToSourcePage(int sourcePageNo) {
  973.     _sourcePageNo = sourcePageNo;
  974.     _pageNo = 1;
  975.     _previousChapterTotalPages.clear();
  976.     updateGurbaniLists();
  977.   }
  978.  
  979.   scrollToPosition() {
  980.     var p = _itemPositionListener.itemPositions.value;
  981.     // print("======================================================");
  982.     // print(p.first.index);
  983.     // print(p.last.index);
  984.     WidgetsBinding.instance.addPostFrameCallback((_) async {
  985.       await Future.delayed(const Duration(milliseconds: 100));
  986.       _itemScrollController.scrollTo(
  987.           index: p.last.index, duration: const Duration(milliseconds: 100));
  988.     });
  989.     // _itemScrollController.scrollTo(index: p.first.index, duration: const Duration(milliseconds: 100));
  990.   }
  991.  
  992.   @override
  993.   Widget build(BuildContext context) {
  994.     final Size mqSize = MediaQuery.of(context).size;
  995.     print(widget.bookNo);
  996.     print("=================================");
  997.     // print(searchedAng.baaniLines.first.sp);
  998.     print(widget.searchedBaaniLine?.sourcePage);
  999.     return SafeArea(
  1000.       child: Scaffold(
  1001.         backgroundColor: nightmodevalue ? whiteColor : blackColor,
  1002.         drawer: Drawer(
  1003.           width: mqSize.width * 0.8,
  1004.           child: ListView(
  1005.             children: _isNitnem
  1006.                 ? [
  1007.                     const SizedBox(height: 15),
  1008.                     const Row(
  1009.                       children: [
  1010.                         // Logo
  1011.                         Padding(
  1012.                           padding: EdgeInsets.only(left: 18.0),
  1013.                           child: Icon(
  1014.                             Icons.info,
  1015.                             color: Colors.red, // specify color if needed
  1016.                             size: 26, // specify size if needed
  1017.                           ),
  1018.                         ),
  1019.                         // Data Sources text
  1020.  
  1021.                         Padding(
  1022.                           padding:
  1023.                               EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
  1024.                           child: Text(
  1025.                             'Data Sources: Sundar Gutka',
  1026.                             overflow: TextOverflow.ellipsis,
  1027.                             style: TextStyle(
  1028.                                 color: blackColor,
  1029.                                 fontSize: 18,
  1030.                                 fontWeight: FontWeight.bold),
  1031.                           ),
  1032.                         ),
  1033.                       ],
  1034.                     ),
  1035.                     const SizedBox(height: 10),
  1036.                     Row(
  1037.                       children: [
  1038.                         const Padding(
  1039.                           padding: EdgeInsets.only(left: 18.0),
  1040.                           child: Icon(
  1041.                             Icons.info,
  1042.                             color: Colors.red, // specify color if needed
  1043.                             size: 26, // specify size if needed
  1044.                           ),
  1045.                         ),
  1046.                         const SizedBox(width: 10),
  1047.                         Text(
  1048.                           'Baani: ${_title}',
  1049.                           style: const TextStyle(
  1050.                               color: blackColor,
  1051.                               fontSize: 18,
  1052.                               fontWeight: FontWeight.bold),
  1053.                         ),
  1054.                       ],
  1055.                     ),
  1056.                     const SizedBox(height: 15),
  1057.                     const Divider(
  1058.                       height: 1,
  1059.                       color: blackColor,
  1060.                     ),
  1061.                     const SizedBox(height: 20),
  1062.  
  1063.                     const Padding(
  1064.                       padding: EdgeInsets.only(left: 18.0, top: 10),
  1065.                       child: Text(
  1066.                         'Translations : -',
  1067.                         style: TextStyle(
  1068.                           color: blackColor,
  1069.                           fontSize: 18,
  1070.                           fontWeight: FontWeight.bold,
  1071.                         ),
  1072.                       ),
  1073.                     ),
  1074.                     // const SizedBox(height: 15),
  1075.  
  1076.                     const SizedBox(height: 10),
  1077.                     ListTile(
  1078.                       title: const Text('English Transliteration',
  1079.                           style: TextStyle(
  1080.                               fontWeight: FontWeight.bold, fontSize: 18)),
  1081.                       trailing: Switch(
  1082.                         value: _showEnglishTransliteration,
  1083.                         onChanged: (value) {
  1084.                           _showEnglishTransliteration = value;
  1085.                           prefs.setBool('showEnglishTransliteration', value);
  1086.                           _pageNo = 1;
  1087.                           _loadedLines = 0;
  1088.                           calculatedPages.clear();
  1089.                           resetLinesPerPage();
  1090.                         },
  1091.                       ),
  1092.                     ),
  1093.                     if (!Contexts.nitnemEngTranslationExceptions
  1094.                         .contains(_nitnemId))
  1095.                       ListTile(
  1096.                         title: const Text('English Translation',
  1097.                             style: TextStyle(
  1098.                                 fontWeight: FontWeight.bold, fontSize: 18)),
  1099.                         trailing: Switch(
  1100.                           value: _showEnglishTranslation,
  1101.                           onChanged: (value) {
  1102.                             _showEnglishTranslation = value;
  1103.                             prefs.setBool('showEnglishTranslation', value);
  1104.                             _pageNo = 1;
  1105.                             _loadedLines = 0;
  1106.                             calculatedPages.clear();
  1107.                             resetLinesPerPage();
  1108.                           },
  1109.                         ),
  1110.                       ),
  1111.                     if (!Contexts.nitnemPunTranslationExceptions
  1112.                         .contains(_nitnemId))
  1113.                       ListTile(
  1114.                         title: const Text('Punjabi Translation',
  1115.                             style: TextStyle(
  1116.                                 fontWeight: FontWeight.bold, fontSize: 18)),
  1117.                         trailing: Switch(
  1118.                           value: _showPunjabiTranslation,
  1119.                           onChanged: (value) {
  1120.                             _showPunjabiTranslation = value;
  1121.                             prefs.setBool('showPunjabiTranslation', value);
  1122.                             _pageNo = 1;
  1123.                             _loadedLines = 0;
  1124.                             calculatedPages.clear();
  1125.                             resetLinesPerPage();
  1126.                           },
  1127.                         ),
  1128.                       ),
  1129.                     if (!Contexts.nitnemPTTranslationExceptions
  1130.                         .contains(_nitnemId))
  1131.                       ListTile(
  1132.                         title: const Text('Punjabi Teeka',
  1133.                             style: TextStyle(
  1134.                                 fontWeight: FontWeight.bold, fontSize: 18)),
  1135.                         trailing: Switch(
  1136.                           value: _showPunjabiTeekaTranslation,
  1137.                           onChanged: (value) {
  1138.                             _showPunjabiTeekaTranslation = value;
  1139.                             prefs.setBool('showPunjabiTeekaTranslation', value);
  1140.                             _pageNo = 1;
  1141.                             _loadedLines = 0;
  1142.                             calculatedPages.clear();
  1143.                             resetLinesPerPage();
  1144.                           },
  1145.                         ),
  1146.                       ),
  1147.                     if (!Contexts.nitnemFTTranslationExceptions
  1148.                         .contains(_nitnemId))
  1149.                       ListTile(
  1150.                         title: const Text('Faridkot Teeka',
  1151.                             style: TextStyle(
  1152.                                 fontWeight: FontWeight.bold, fontSize: 18)),
  1153.                         trailing: Switch(
  1154.                           value: _showFaridkotTeekaTranslation,
  1155.                           onChanged: (value) {
  1156.                             _showFaridkotTeekaTranslation = value;
  1157.                             prefs.setBool(
  1158.                                 'showFaridkotTeekaTranslation', value);
  1159.                             _pageNo = 1;
  1160.                             _loadedLines = 0;
  1161.                             calculatedPages.clear();
  1162.                             resetLinesPerPage();
  1163.                           },
  1164.                         ),
  1165.                       ),
  1166.                     const Divider(
  1167.                       height: 1,
  1168.                       color: blackColor,
  1169.                     ),
  1170.                     const SizedBox(height: 15),
  1171.                     const Padding(
  1172.                       padding:
  1173.                           EdgeInsets.only(left: 18.0, top: 10.0, bottom: 3.0),
  1174.                       child: Text(
  1175.                         'Select Baani Language :',
  1176.                         style: TextStyle(
  1177.                           color: blackColor,
  1178.                           fontSize: 18,
  1179.                           fontWeight: FontWeight.bold,
  1180.                         ),
  1181.                       ),
  1182.                     ),
  1183.                     const SizedBox(height: 10),
  1184.                     ListTile(
  1185.                       title: const Text(
  1186.                         'Language ',
  1187.                         style: TextStyle(
  1188.                           color: blackColor,
  1189.                           fontSize: 18,
  1190.                           fontWeight: FontWeight.bold,
  1191.                         ),
  1192.                       ),
  1193.                       trailing: DropdownButton<Languages>(
  1194.                         value: _language,
  1195.                         onChanged: (Languages? newValue) {
  1196.                           _language = newValue!;
  1197.                           prefs.setInt('language', newValue.index);
  1198.                           _pageNo = 1;
  1199.                           _loadedLines = 0;
  1200.                           calculatedPages.clear();
  1201.                           resetLinesPerPage();
  1202.                         },
  1203.                         items: Languages.values
  1204.                             .map<DropdownMenuItem<Languages>>(
  1205.                                 (Languages value) {
  1206.                           return DropdownMenuItem<Languages>(
  1207.                             value: value,
  1208.                             child: Text(
  1209.                               value.toString().split('.').last,
  1210.                               style: const TextStyle(
  1211.                                   fontWeight: FontWeight.bold, fontSize: 18),
  1212.                             ),
  1213.                           );
  1214.                         }).toList(),
  1215.                       ),
  1216.                     ),
  1217.                   ]
  1218.                 : _bookNo == 1
  1219.                     ? [
  1220.                         const SizedBox(height: 20),
  1221.                         const Row(
  1222.                           children: [
  1223.                             // Logo
  1224.                             Padding(
  1225.                               padding: EdgeInsets.only(left: 18.0),
  1226.                               child: Icon(
  1227.                                 Icons.info,
  1228.                                 color: Colors.red, // specify color if needed
  1229.                                 size: 24, // specify size if needed
  1230.                               ),
  1231.                             ),
  1232.                             // Data Sources text
  1233.  
  1234.                             Padding(
  1235.                               padding: EdgeInsets.only(
  1236.                                   left: 10.0, top: 5, bottom: 5),
  1237.                               child: Text(
  1238.                                 'Source: Guru Granth Sahib Ji',
  1239.                                 overflow: TextOverflow.ellipsis,
  1240.                                 style: TextStyle(
  1241.                                     color: blackColor,
  1242.                                     fontSize: 18,
  1243.                                     fontWeight: FontWeight.bold),
  1244.                               ),
  1245.                             ),
  1246.                           ],
  1247.                         ),
  1248.                         Row(
  1249.                           children: [
  1250.                             // Logo
  1251.                             const Padding(
  1252.                               padding: EdgeInsets.only(left: 18.0),
  1253.                               child: Icon(
  1254.                                 Icons.info,
  1255.                                 color: Colors.red, // specify color if needed
  1256.                                 size: 24, // specify size if needed
  1257.                               ),
  1258.                             ),
  1259.                             // Data Sources text
  1260.  
  1261.                             // woking for AK
  1262.  
  1263.                             _searchviewm
  1264.                                 ? Padding(
  1265.                                     padding: const EdgeInsets.only(
  1266.                                         left: 10.0, top: 5, bottom: 5),
  1267.                                     child: Text(
  1268.                                       'Ang - : ${widget.searchedAng}',
  1269.                                       style: const TextStyle(
  1270.                                           color: blackColor,
  1271.                                           fontSize: 18,
  1272.                                           fontWeight: FontWeight.bold),
  1273.                                     ))
  1274.                                 : Padding(
  1275.                                     padding: const EdgeInsets.only(
  1276.                                         left: 10.0, top: 5, bottom: 5),
  1277.                                     child: Text(
  1278.                                       'Ang - : $_sourcePageNo',
  1279.                                       style: const TextStyle(
  1280.                                           color: blackColor,
  1281.                                           fontSize: 18,
  1282.                                           fontWeight: FontWeight.bold),
  1283.                                     )),
  1284.                           ],
  1285.                         ),
  1286.                         const SizedBox(height: 10),
  1287.                         const Divider(
  1288.                           height: 1,
  1289.                           color: blackColor,
  1290.                         ),
  1291.                         const SizedBox(height: 10),
  1292.                         const Padding(
  1293.                           padding: EdgeInsets.only(left: 18.0, top: 10),
  1294.                           child: Text(
  1295.                             'Translations :',
  1296.                             style: TextStyle(
  1297.                               color: blackColor,
  1298.                               fontSize: 18,
  1299.                               fontWeight: FontWeight.bold,
  1300.                             ),
  1301.                           ),
  1302.                         ),
  1303.                         const SizedBox(height: 15),
  1304.  
  1305.                         ListTile(
  1306.                           title: const Text(
  1307.                             'English Transliteration',
  1308.                             style: TextStyle(
  1309.                               color: blackColor,
  1310.                               fontSize: 18,
  1311.                               fontWeight: FontWeight.bold,
  1312.                             ),
  1313.                           ),
  1314.                           trailing: Switch(
  1315.                             value: _showEnglishTransliteration,
  1316.                             onChanged: (value) {
  1317.                               _showEnglishTransliteration = value;
  1318.                               prefs.setBool(
  1319.                                   'showEnglishTransliteration', value);
  1320.                               _pageNo = 1;
  1321.                               _loadedLines = 0;
  1322.                               calculatedPages.clear();
  1323.                               resetLinesPerPage();
  1324.                               if (widget.searchView) {
  1325.                                 scrollToPosition();
  1326.                               }
  1327.                             },
  1328.                           ),
  1329.                         ),
  1330.                         ListTile(
  1331.                           title: const Text(
  1332.                             'English Translation',
  1333.                             style: TextStyle(
  1334.                               color: blackColor,
  1335.                               fontSize: 18,
  1336.                               fontWeight: FontWeight.bold,
  1337.                             ),
  1338.                           ),
  1339.                           trailing: Switch(
  1340.                             value: _showEnglishTranslation,
  1341.                             onChanged: (value) {
  1342.                               _showEnglishTranslation = value;
  1343.                               prefs.setBool('showEnglishTranslation', value);
  1344.                               _pageNo = 1;
  1345.                               _loadedLines = 0;
  1346.                               calculatedPages.clear();
  1347.                               resetLinesPerPage();
  1348.                               if (widget.searchView) {
  1349.                                 scrollToPosition();
  1350.                               }
  1351.                             },
  1352.                           ),
  1353.                         ),
  1354.                         ListTile(
  1355.                           title: const Text(
  1356.                             'Punjabi Translation',
  1357.                             style: TextStyle(
  1358.                               color: blackColor,
  1359.                               fontSize: 18,
  1360.                               fontWeight: FontWeight.bold,
  1361.                             ),
  1362.                           ),
  1363.                           trailing: Switch(
  1364.                             value: _showPunjabiTranslation,
  1365.                             onChanged: (value) {
  1366.                               _showPunjabiTranslation = value;
  1367.                               prefs.setBool('showPunjabiTranslation', value);
  1368.                               _pageNo = 1;
  1369.                               _loadedLines = 0;
  1370.                               calculatedPages.clear();
  1371.                               resetLinesPerPage();
  1372.                               if (widget.searchView) {
  1373.                                 scrollToPosition();
  1374.                               }
  1375.                             },
  1376.                           ),
  1377.                         ),
  1378.                         ListTile(
  1379.                           title: const Text(
  1380.                             'Punjabi Teeka',
  1381.                             style: TextStyle(
  1382.                               color: blackColor,
  1383.                               fontSize: 18,
  1384.                               fontWeight: FontWeight.bold,
  1385.                             ),
  1386.                           ),
  1387.                           trailing: Switch(
  1388.                             value: _showPunjabiTeekaTranslation,
  1389.                             onChanged: (value) {
  1390.                               _showPunjabiTeekaTranslation = value;
  1391.                               prefs.setBool(
  1392.                                   'showPunjabiTeekaTranslation', value);
  1393.                               _pageNo = 1;
  1394.                               _loadedLines = 0;
  1395.                               calculatedPages.clear();
  1396.                               resetLinesPerPage();
  1397.                               if (widget.searchView) {
  1398.                                 scrollToPosition();
  1399.                               }
  1400.                             },
  1401.                           ),
  1402.                         ),
  1403.                         ListTile(
  1404.                           title: const Text(
  1405.                             'Faridkot Teeka',
  1406.                             style: TextStyle(
  1407.                               color: blackColor,
  1408.                               fontSize: 18,
  1409.                               fontWeight: FontWeight.bold,
  1410.                             ),
  1411.                           ),
  1412.                           trailing: Switch(
  1413.                             value: _showFaridkotTeekaTranslation,
  1414.                             onChanged: (value) {
  1415.                               _showFaridkotTeekaTranslation = value;
  1416.                               prefs.setBool(
  1417.                                   'showFaridkotTeekaTranslation', value);
  1418.                               _pageNo = 1;
  1419.                               _loadedLines = 0;
  1420.                               calculatedPages.clear();
  1421.                               resetLinesPerPage();
  1422.                               if (widget.searchView) {
  1423.                                 scrollToPosition();
  1424.                               }
  1425.                             },
  1426.                           ),
  1427.                         ),
  1428.                         // ListTile(
  1429.                         //   title: const Text('Hindi Translation'),
  1430.                         //   trailing: Switch(
  1431.                         //     value: _showHindiTranslation,
  1432.                         //     onChanged: (value) {
  1433.                         //         _showHindiTranslation = value;
  1434.                         //         resetLinesPerPage();
  1435.                         //     },
  1436.                         //   ),
  1437.                         // ),
  1438.                         // ListTile(
  1439.                         //   title: const Text('Hindi Teeka'),
  1440.                         //   trailing: Switch(
  1441.                         //     value: _showHindiTeekaTranslation,
  1442.                         //     onChanged: (value) {
  1443.                         //         _showHindiTeekaTranslation = value;
  1444.                         //         resetLinesPerPage();
  1445.                         //     },
  1446.                         //   ),
  1447.                         // ),
  1448.                         const SizedBox(height: 10),
  1449.                         const Divider(
  1450.                           height: 1,
  1451.                           color: blackColor,
  1452.                         ),
  1453.                         const SizedBox(height: 15),
  1454.                         const Padding(
  1455.                           padding: EdgeInsets.only(
  1456.                               left: 18.0, top: 10.0, bottom: 3.0),
  1457.                           child: Text(
  1458.                             'Select Baani Language :',
  1459.                             style: TextStyle(
  1460.                               color: blackColor,
  1461.                               fontSize: 18,
  1462.                               fontWeight: FontWeight.bold,
  1463.                             ),
  1464.                           ),
  1465.                         ),
  1466.                         const SizedBox(height: 10),
  1467.                         ListTile(
  1468.                           title: const Text(
  1469.                             'Language',
  1470.                             style: TextStyle(
  1471.                               color: blackColor,
  1472.                               fontSize: 18,
  1473.                               fontWeight: FontWeight.bold,
  1474.                             ),
  1475.                           ),
  1476.                           trailing: DropdownButton<Languages>(
  1477.                             value: _language,
  1478.                             onChanged: (Languages? newValue) {
  1479.                               _language = newValue!;
  1480.                               prefs.setInt('language', newValue.index);
  1481.                               _pageNo = 1;
  1482.                               _loadedLines = 0;
  1483.                               calculatedPages.clear();
  1484.                               resetLinesPerPage();
  1485.                             },
  1486.                             items: Languages.values
  1487.                                 .map<DropdownMenuItem<Languages>>(
  1488.                                     (Languages value) {
  1489.                               return DropdownMenuItem<Languages>(
  1490.                                 value: value,
  1491.                                 child: Text(value.toString().split('.').last,
  1492.                                     style: const TextStyle(
  1493.                                         fontWeight: FontWeight.bold,
  1494.                                         fontSize: 18)),
  1495.                               );
  1496.                             }).toList(),
  1497.                           ),
  1498.                         ),
  1499.                       ]
  1500.                     : [
  1501.                         const SizedBox(height: 20),
  1502.                         const Row(
  1503.                           children: [
  1504.                             // Logo
  1505.                             Padding(
  1506.                               padding: EdgeInsets.only(left: 10.0),
  1507.                               child: Icon(
  1508.                                 Icons.info,
  1509.                                 color: Colors.red, // specify color if needed
  1510.                                 size: 26, // specify size if needed
  1511.                               ),
  1512.                             ),
  1513.                             // Data Sources text
  1514.  
  1515.                             Padding(
  1516.                               padding:
  1517.                                   EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
  1518.                               child: Text(
  1519.                                 'Source: Dasam Granth Sahib',
  1520.                                 overflow: TextOverflow.ellipsis,
  1521.                                 style: TextStyle(
  1522.                                     color: blackColor,
  1523.                                     fontSize: 18,
  1524.                                     fontWeight: FontWeight.bold),
  1525.                               ),
  1526.                             ),
  1527.                           ],
  1528.                         ),
  1529.                         Row(
  1530.                           children: [
  1531.                             // Logo
  1532.                             const Padding(
  1533.                               padding: EdgeInsets.only(
  1534.                                 left: 10.0,
  1535.                               ),
  1536.                               child: Icon(
  1537.                                 Icons.info,
  1538.                                 color: Colors.red, // specify color if needed
  1539.                                 size: 24, // specify size if needed
  1540.                               ),
  1541.                             ),
  1542.                             // Data Sources text
  1543.  
  1544.                             _searchviewm
  1545.                                 ? Padding(
  1546.                                     padding: const EdgeInsets.only(
  1547.                                         left: 10.0, top: 5, bottom: 5),
  1548.                                     child: Text(
  1549.                                       'Ang - : ${widget.searchedAng}',
  1550.                                       style: const TextStyle(
  1551.                                           color: blackColor,
  1552.                                           fontSize: 18,
  1553.                                           fontWeight: FontWeight.bold),
  1554.                                     ))
  1555.                                 : Padding(
  1556.                                     padding: const EdgeInsets.only(
  1557.                                         left: 10.0, top: 5, bottom: 5),
  1558.                                     child: Text(
  1559.                                       'Ang - : $_sourcePageNo',
  1560.                                       style: const TextStyle(
  1561.                                           color: blackColor,
  1562.                                           fontSize: 18,
  1563.                                           fontWeight: FontWeight.bold),
  1564.                                     )),
  1565.  
  1566.                             //
  1567.                           ],
  1568.                         ),
  1569.                         const SizedBox(height: 10),
  1570.                         const Divider(
  1571.                           height: 1,
  1572.                           color: blackColor,
  1573.                         ),
  1574.                         const SizedBox(height: 20),
  1575.                         const Padding(
  1576.                           padding: EdgeInsets.only(left: 18.0, top: 10),
  1577.                           child: Text(
  1578.                             'Translations : -',
  1579.                             style: TextStyle(
  1580.                               color: blackColor,
  1581.                               fontSize: 18,
  1582.                               fontWeight: FontWeight.bold,
  1583.                             ),
  1584.                           ),
  1585.                         ),
  1586.                         const SizedBox(height: 10),
  1587.                         ListTile(
  1588.                           title: const Text(
  1589.                             'English Transliteration',
  1590.                             style: TextStyle(
  1591.                               color: blackColor,
  1592.                               fontSize: 18,
  1593.                               fontWeight: FontWeight.bold,
  1594.                             ),
  1595.                           ),
  1596.                           trailing: Switch(
  1597.                             value: _showEnglishTransliteration,
  1598.                             onChanged: (value) {
  1599.                               _showEnglishTransliteration = value;
  1600.                               prefs.setBool(
  1601.                                   'showEnglishTransliteration', value);
  1602.                               _pageNo = 1;
  1603.                               _loadedLines = 0;
  1604.                               calculatedPages.clear();
  1605.                               resetLinesPerPage();
  1606.                               if (widget.searchView) {
  1607.                                 scrollToPosition();
  1608.                               }
  1609.                             },
  1610.                           ),
  1611.                         ),
  1612.                         ListTile(
  1613.                           title: const Text(
  1614.                             'English Translation',
  1615.                             style: TextStyle(
  1616.                               color: blackColor,
  1617.                               fontSize: 18,
  1618.                               fontWeight: FontWeight.bold,
  1619.                             ),
  1620.                           ),
  1621.                           trailing: Switch(
  1622.                             value: _showEnglishTranslation,
  1623.                             onChanged: (value) {
  1624.                               _showEnglishTranslation = value;
  1625.                               prefs.setBool('showEnglishTranslation', value);
  1626.                               _pageNo = 1;
  1627.                               _loadedLines = 0;
  1628.                               calculatedPages.clear();
  1629.                               resetLinesPerPage();
  1630.                               if (widget.searchView) {
  1631.                                 scrollToPosition();
  1632.                               }
  1633.                             },
  1634.                           ),
  1635.                         ),
  1636.                         ListTile(
  1637.                           title: const Text(
  1638.                             'Punjabi Translation',
  1639.                             style: TextStyle(
  1640.                               color: blackColor,
  1641.                               fontSize: 18,
  1642.                               fontWeight: FontWeight.bold,
  1643.                             ),
  1644.                           ),
  1645.                           trailing: Switch(
  1646.                             value: _showPunjabiTranslation,
  1647.                             onChanged: (value) {
  1648.                               _showPunjabiTranslation = value;
  1649.                               prefs.setBool('showPunjabiTranslation', value);
  1650.                               _pageNo = 1;
  1651.                               _loadedLines = 0;
  1652.                               calculatedPages.clear();
  1653.                               resetLinesPerPage();
  1654.                               if (widget.searchView) {
  1655.                                 scrollToPosition();
  1656.                               }
  1657.                             },
  1658.                           ),
  1659.                         ),
  1660.                         const SizedBox(height: 10),
  1661.                         const Divider(
  1662.                           height: 1,
  1663.                           color: blackColor,
  1664.                         ),
  1665.                         const SizedBox(height: 10),
  1666.                         const Padding(
  1667.                           padding: EdgeInsets.only(
  1668.                               left: 18.0, top: 10.0, bottom: 3.0),
  1669.                           child: Text(
  1670.                             'Select Baani Language :',
  1671.                             style: TextStyle(
  1672.                               color: blackColor,
  1673.                               fontSize: 18,
  1674.                               fontWeight: FontWeight.bold,
  1675.                             ),
  1676.                           ),
  1677.                         ),
  1678.                         const SizedBox(height: 10),
  1679.                         ListTile(
  1680.                           title: const Text(
  1681.                             'Language',
  1682.                             style: TextStyle(
  1683.                               color: blackColor,
  1684.                               fontSize: 19,
  1685.                               fontWeight: FontWeight.bold,
  1686.                             ),
  1687.                           ),
  1688.                           trailing: DropdownButton<Languages>(
  1689.                             value: _language,
  1690.                             onChanged: (Languages? newValue) {
  1691.                               _language = newValue!;
  1692.                               prefs.setInt('language', newValue.index);
  1693.                               _pageNo = 1;
  1694.                               _loadedLines = 0;
  1695.                               calculatedPages.clear();
  1696.                               resetLinesPerPage();
  1697.                               // if(!value) {
  1698.                               //   scrollToPosition();
  1699.                               // }
  1700.                             },
  1701.                             items: Languages.values
  1702.                                 .map<DropdownMenuItem<Languages>>(
  1703.                                     (Languages value) {
  1704.                               return DropdownMenuItem<Languages>(
  1705.                                 value: value,
  1706.                                 child: Text(value.toString().split('.').last,
  1707.                                     style: const TextStyle(
  1708.                                         fontWeight: FontWeight.bold,
  1709.                                         fontSize: 18)),
  1710.                               );
  1711.                             }).toList(),
  1712.                           ),
  1713.                         ),
  1714.                       ],
  1715.           ),
  1716.         ),
  1717.         appBar: AppBar(
  1718.           title: Text(widget.title ?? 'Gurbani'),
  1719.           actions: [
  1720.             if (!widget.searchView && !_isNitnem)
  1721.               IconButton(
  1722.                 icon: const Icon(Icons.search),
  1723.                 onPressed: () {
  1724.                   _showSearch = !_showSearch;
  1725.                   setState(() {});
  1726.                 },
  1727.               ),
  1728.             widget.searchView && widget.searchedBaaniLine != null
  1729.                 ? IconButton(
  1730.                     icon: Icon(
  1731.                       _isBookMarked ? Icons.favorite : Icons.favorite_outline,
  1732.                       color: whiteColor,
  1733.                     ),
  1734.                     onPressed: () async {
  1735.                       await saveToBookmarks(widget.searchedBaaniLine!);
  1736.                       setState(() {
  1737.                         // _isBookMarked = !_isBookMarked;
  1738.                       });
  1739.                     },
  1740.                   )
  1741.                 : Container(),
  1742.             IconButton(
  1743.               icon: const Icon(
  1744.                 Icons.build,
  1745.                 color: whiteColor,
  1746.               ),
  1747.               onPressed: () {
  1748.                 Helper.toScreen(context, const Settings());
  1749.               },
  1750.             ),
  1751.           ],
  1752.         ),
  1753.         body: widget.searchView
  1754.             ? BaaniPageView(
  1755.                 baaniLines: searchedAng,
  1756.                 linesPerPage: searchedAng.count,
  1757.                 language: _language,
  1758.                 showEnglishTransliteration: _showEnglishTransliteration,
  1759.                 showEnglishTranslation: _showEnglishTranslation,
  1760.                 showPunjabiTranslation: _showPunjabiTranslation,
  1761.                 showPunjabiTeekaTranslation: _showPunjabiTeekaTranslation,
  1762.                 showFaridkotTeekaTranslation: _showFaridkotTeekaTranslation,
  1763.                 showHindiTranslation: _showHindiTranslation,
  1764.                 showHindiTeekaTranslation: _showHindiTeekaTranslation,
  1765.                 // language: _language,
  1766.                 isLoading: _isLoading,
  1767.                 searchedLine: widget.searchedBaaniLine,
  1768.                 showPageNo: false,
  1769.                 itemPositionListener: _itemPositionListener,
  1770.                 itemScrollController: _itemScrollController, isbold: isbold,
  1771.                 nightmodevalue: nightmodevalue,
  1772.               )
  1773.             : Stack(
  1774.                 children: [
  1775.                   Container(
  1776.                     color: nightmodevalue ? whiteColor : blackColor,
  1777.                     height: Contexts.size!.height -
  1778.                         _getAppbarAndStatusBarHeight() +
  1779.                         _extraBottomPadding,
  1780.                     width: Contexts.size!.width,
  1781.                     child: Center(
  1782.                       child: CalculatedViewWidget(
  1783.                         baaniLines: calculatedPages.isEmpty ||
  1784.                                 calculatedPages.length <= 1 ||
  1785.                                 calculatedPages.length <= _pageNo
  1786.                             ? CalculatedItems(
  1787.                                 textSpans: List.empty(growable: true),
  1788.                                 pageNo: 0,
  1789.                                 totalPages: 0)
  1790.                             : calculatedPages.elementAt(_pageNo),
  1791.                         isLoading: _isLoading,
  1792.                       ),
  1793.                     ),
  1794.                   ),
  1795.  
  1796.                   SizedBox(
  1797.                     width: Contexts.size!.width,
  1798.                     height: Contexts.size!.height -
  1799.                         _getAppbarAndStatusBarHeight() +
  1800.                         _extraBottomPadding,
  1801.                     child: GestureDetector(
  1802.                       child: FlipWidget(
  1803.                         key: _flipKey,
  1804.                         textureSize: Size(
  1805.                                 Contexts.size!.width,
  1806.                                 Contexts.size!.height -
  1807.                                     _getAppbarAndStatusBarHeight() +
  1808.                                     _extraBottomPadding) *
  1809.                             1,
  1810.                         // leftToRight: true, //
  1811.                         child: Container(
  1812.                           color: nightmodevalue ? whiteColor : blackColor,
  1813.                           child: Center(
  1814.                             child: CalculatedViewWidget(
  1815.                               baaniLines: calculatedPages.isEmpty
  1816.                                   ? CalculatedItems(
  1817.                                       textSpans: List.empty(growable: true),
  1818.                                       pageNo: 0,
  1819.                                       totalPages: 0)
  1820.                                   : calculatedPages.elementAt(
  1821.                                       (_pageNo < 1 ? 1 : _pageNo) - 1),
  1822.                               isLoading: _isLoading,
  1823.                             ),
  1824.                           ),
  1825.                         ),
  1826.                       ),
  1827.                       onHorizontalDragStart: (details) {
  1828.                         _oldPosition = details.globalPosition;
  1829.                         _flipKey.currentState?.startFlip();
  1830.                       },
  1831.                       onHorizontalDragUpdate: (details) {
  1832.                         Offset off = details.globalPosition - _oldPosition;
  1833.                         double tilt = 1 / _clampMin((-off.dy + 20) / 100);
  1834.                         double percent =
  1835.                             math.max(0, -off.dx / Contexts.size!.width * 1.4);
  1836.                         percent = percent - percent / 2 * (1 - 1 / tilt);
  1837.                         _flipKey.currentState?.flip(percent, tilt);
  1838.                         if (details.primaryDelta! > 0) {
  1839.                           isLeftToRight = true;
  1840.                         } else if (details.primaryDelta! < 0) {
  1841.                           isLeftToRight = false;
  1842.                         } else {
  1843.                           isLeftToRight = null;
  1844.                         }
  1845.                         _isDragging = true;
  1846.                       },
  1847.                       onHorizontalDragEnd: (details) {
  1848.                         if (!_isDragging) {
  1849.                           return;
  1850.                         }
  1851.                         _isDragging = false;
  1852.                         _flipKey.currentState?.stopFlip();
  1853.                         if (isLeftToRight == true) {
  1854.                           if (_sourcePageNo == 1 && _pageNo == 1) {
  1855.                             return;
  1856.                           } else if (_sourcePageNo >= 1 && _pageNo == 1) {
  1857.                             _sourcePageNo -= 1;
  1858.                             if (_sourcePageNo < 1) {
  1859.                               _sourcePageNo = 1;
  1860.                             }
  1861.                             _pageNo = _previousChapterTotalPages.isEmpty
  1862.                                 ? 0
  1863.                                 : _previousChapterTotalPages.last;
  1864.                             if (_previousChapterTotalPages.isNotEmpty) {
  1865.                               _previousChapterTotalPages.removeLast();
  1866.                             }
  1867.                             // print(_history.length);
  1868.                             if (_history.length > 0) {
  1869.                               calculatedPages.clear();
  1870.                               calculatedPages
  1871.                                   .addAll(_history.last.calculatedItems);
  1872.                               currentAng = _history.last.lines;
  1873.                               _loadedLines = _history.last.loadedLines;
  1874.                               _pageNo = _history.last.pageNo;
  1875.                               _sourcePageNo = _history.last.sourcePageNo;
  1876.                               _history.last.unlink();
  1877.                             }
  1878.                           } else if (_sourcePageNo >= 1 && _pageNo >= 1) {
  1879.                             _pageNo -= 1;
  1880.                             // print(_pageNo);
  1881.                           }
  1882.                         } else if (isLeftToRight == false) {
  1883.                           _pageNo += 1;
  1884.                         }
  1885.                         if (isLeftToRight != null) {
  1886.                           if (_isNitnem) {
  1887.                             // if(currentAng.baaniLines.length - (_linesPerPage * (_pageNo)) <0){
  1888.                             //   _pageNo = (currentAng.baaniLines.length/_linesPerPage).ceil();
  1889.                             //   // return;
  1890.                             // }
  1891.  
  1892.                             if (_pageNo > calculatedPages.length) {
  1893.                               _pageNo = calculatedPages.length;
  1894.                               return;
  1895.                             }
  1896.  
  1897.                             updateNitnemLists();
  1898.                           } else {
  1899.                             if (_loadSourceLines) {
  1900.                               if (_loadedLines >= currentAng.count) {
  1901.                                 if (calculatedPages.length - (_pageNo) < 0) {
  1902.                                   HistoryItem history = HistoryItem(
  1903.                                       calculatedItems: calculatedPages.toList(),
  1904.                                       lines: currentAng,
  1905.                                       sourcePageNo: _sourcePageNo,
  1906.                                       pageNo: _pageNo - 1,
  1907.                                       loadedLines: _loadedLines);
  1908.                                   _history.add(history);
  1909.                                   _pageNo = 1;
  1910.                                   _sourcePageNo += 1;
  1911.                                   calculatedPages.clear();
  1912.                                   _loadedLines = 0;
  1913.                                   // return;
  1914.                                 } else {
  1915.                                   // return;
  1916.                                 }
  1917.                               }
  1918.  
  1919.                               // if((currentAng.baaniLines.length - (_linesPerPage * (_pageNo)) <0) && (currentAng.baaniLines.length - (_linesPerPage * (_pageNo-1)) <=0)){
  1920.                               //   _pageNo = 1;
  1921.                               //   _sourcePageNo += 1;
  1922.                               //   // return;
  1923.                               // }
  1924.                               // updateGurbaniLists();
  1925.                               // return;
  1926.                             }
  1927.                             updateGurbaniLists(); //kro
  1928.                           }
  1929.                           setState(() {});
  1930.                         }
  1931.                         // Navigator.push(
  1932.                         //     context,
  1933.                         //     MaterialPageRoute(
  1934.                         //         builder: (context) => HomeScreen(
  1935.                         //               offset: widget.offset + 10,
  1936.                         //             )));
  1937.                       },
  1938.                       onHorizontalDragCancel: () {
  1939.                         _flipKey.currentState?.stopFlip();
  1940.                       },
  1941.                     ),
  1942.                   ),
  1943.  
  1944.                   // Positioned(
  1945.                   //     bottom: 10,
  1946.                   //     right: 10,
  1947.                   //     child: Column(
  1948.                   //       children: [
  1949.                   //         IconButton(
  1950.                   //             onPressed: () => Navigator.push(
  1951.                   //                 context,
  1952.                   //                 MaterialPageRoute(
  1953.                   //                     builder: (context) => HomeScreen(
  1954.                   //                           offset: widget.offset - 10,
  1955.                   //                         ))),
  1956.                   //             icon: const Icon(
  1957.                   //               Icons.arrow_back,
  1958.                   //               color: Colors.white,
  1959.                   //             )),
  1960.                   //         IconButton(
  1961.                   //             onPressed: () => Navigator.push(
  1962.                   //                 context,
  1963.                   //                 MaterialPageRoute(
  1964.                   //                     builder: (context) => HomeScreen(
  1965.                   //                           offset: widget.offset + 10,
  1966.                   //                         ))),
  1967.                   //             icon: const Icon(Icons.arrow_forward,
  1968.                   //                 color: Colors.white)),
  1969.                   //       ],
  1970.                   //     ))
  1971.                 ],
  1972.               ),
  1973.         floatingActionButton: _showSearch
  1974.             ? Container(
  1975.                 margin: EdgeInsets.only(top: 60.h, left: 10.w, right: 10.w),
  1976.                 color: Colors.white.withOpacity(.9),
  1977.                 child: TextField(
  1978.                   controller: _searchController,
  1979.                   textInputAction: TextInputAction.search,
  1980.                   keyboardType: TextInputType.number,
  1981.                   inputFormatters: [
  1982.                     FilteringTextInputFormatter.allow(RegExp(r'^[0-9]+$')),
  1983.                   ],
  1984.                   onSubmitted: (value) {
  1985.                     int inputPageNo = int.parse(value);
  1986.                     if ((_bookNo == 1 &&
  1987.                             (inputPageNo < 1 ||
  1988.                                 inputPageNo > maxvalueofBook1)) ||
  1989.                         (_bookNo == 2 &&
  1990.                             (inputPageNo < 1 ||
  1991.                                 inputPageNo > maxvalueofBook2))) {
  1992.                       if (_bookNo == 1) {
  1993.                         errorMessage =
  1994.                             "Please enter a page number between 1 and $maxvalueofBook1.";
  1995.                       } else if (_bookNo == 2) {
  1996.                         errorMessage =
  1997.                             "Please enter an ang number between 1 and $maxvalueofBook2.";
  1998.                       }
  1999.                       showDialog(
  2000.                         context: context,
  2001.                         builder: (context) {
  2002.                           return AlertDialog(
  2003.                             title: const Text(
  2004.                               "Invalid Input",
  2005.                               style: TextStyle(
  2006.                                   color: Colors.black,
  2007.                                   fontWeight: FontWeight.bold),
  2008.                             ),
  2009.                             content: Text(
  2010.                               errorMessage,
  2011.                               style: const TextStyle(
  2012.                                   color: Colors.black,
  2013.                                   fontWeight: FontWeight.bold),
  2014.                             ),
  2015.                             actions: <Widget>[
  2016.                               TextButton(
  2017.                                 onPressed: () {
  2018.                                   Navigator.of(context).pop();
  2019.                                   _searchController.clear();
  2020.                                 },
  2021.                                 child: const Text("OK"),
  2022.                               ),
  2023.                             ],
  2024.                           );
  2025.                         },
  2026.                       );
  2027.                     } else {
  2028.                       HistoryItem history = HistoryItem(
  2029.                           calculatedItems: calculatedPages.toList(),
  2030.                           lines: currentAng,
  2031.                           sourcePageNo: _sourcePageNo,
  2032.                           pageNo: _pageNo,
  2033.                           loadedLines: _loadedLines);
  2034.                       _history.add(history);
  2035.                       calculatedPages.clear();
  2036.                       _loadedLines = 0;
  2037.                       _sourcePageNo = int.parse(value);
  2038.                       _pageNo = 1;
  2039.                       updateGurbaniLists();
  2040.                       setState(() {
  2041.                         _showSearch = false;
  2042.                         _searchController.clear();
  2043.                       });
  2044.                     }
  2045.                   },
  2046.                   decoration: InputDecoration(
  2047.                     hintText: 'Search',
  2048.                     hintStyle: const TextStyle(
  2049.                         color: Colors.black, fontWeight: FontWeight.bold),
  2050.                     prefixIcon: const Icon(
  2051.                       Icons.search,
  2052.                       color: Colors.black,
  2053.                     ),
  2054.                     suffixIcon: IconButton(
  2055.                       icon: const Icon(
  2056.                         Icons.close,
  2057.                         color: Colors.black,
  2058.                       ),
  2059.                       onPressed: () {
  2060.                         _searchController.clear();
  2061.                         setState(() {
  2062.                           _showSearch = false;
  2063.                         });
  2064.                       },
  2065.                     ),
  2066.                     border: OutlineInputBorder(
  2067.                       borderRadius: BorderRadius.circular(10.r),
  2068.                       borderSide: BorderSide(
  2069.                         width: 1.r,
  2070.                         style: BorderStyle.solid,
  2071.                       ),
  2072.                     ),
  2073.                     filled: true,
  2074.                     contentPadding: EdgeInsets.all(16.r),
  2075.                     fillColor: Colors.white.withOpacity(0.1),
  2076.                   ),
  2077.                   style: const TextStyle(
  2078.                       color: blackColor, fontWeight: FontWeight.bold),
  2079.                 ))
  2080.             : null,
  2081.         floatingActionButtonLocation: FloatingActionButtonLocation.centerTop,
  2082.       ),
  2083.     );
  2084.   }
  2085. }
  2086.  
  2087. class BaaniSearchDelegate extends SearchDelegate<BaaniLineModel> {
  2088.   @override
  2089.   List<Widget> buildActions(BuildContext context) {
  2090.     return [
  2091.       IconButton(
  2092.         icon: const Icon(Icons.clear),
  2093.         onPressed: () {
  2094.           query = '';
  2095.         },
  2096.       ),
  2097.     ];
  2098.   }
  2099.  
  2100.   @override
  2101.   Widget buildLeading(BuildContext context) {
  2102.     return IconButton(
  2103.       icon: const Icon(Icons.arrow_back),
  2104.       onPressed: () => Navigator.of(context).pop(),
  2105.     );
  2106.   }
  2107.  
  2108.   @override
  2109.   Widget buildResults(BuildContext context) {
  2110.     return Container(
  2111.       child: const Center(
  2112.         child: Text('Search Results'),
  2113.       ),
  2114.     );
  2115.   }
  2116.  
  2117.   @override
  2118.   Widget buildSuggestions(BuildContext context) {
  2119.     return Container(
  2120.       child: const Center(
  2121.         child: Text('Enter Page no to show'),
  2122.       ),
  2123.     );
  2124.   }
  2125. }
  2126.  
  2127.  
  2128. /*
  2129. BaaniPageView(
  2130.                     baaniLines: _loadSourceLines || _isNitnem ?
  2131.                                 currentAng.baaniLines.length ~/ (_linesPerPage*(_pageNo)) ==0 ?
  2132.                                   DBResult(baaniLines: List.empty(), count: 0) :
  2133.                                   currentAng.baaniLines.length < _pageNo*_linesPerPage ?
  2134.                                     DBResult(baaniLines: List.empty(), count: 0) :
  2135.                                     DBResult(
  2136.                                       baaniLines: currentAng.baaniLines.sublist(
  2137.                                           _pageNo*_linesPerPage ,
  2138.                                           (_pageNo+1)*_linesPerPage >= currentAng.baaniLines.length ?
  2139.                                             currentAng.baaniLines.length :
  2140.                                             (_pageNo+1)*_linesPerPage),
  2141.                                       count: _linesPerPage) :
  2142.                                 nextAng,
  2143.                     pageNo: (currentAng.count/_linesPerPage).ceil() == _pageNo ? 1 : _pageNo+1,
  2144.                     totalPages: _loadSourceLines || _isNitnem ? (currentAng.count/_linesPerPage).ceil() : (nextAng.count/_linesPerPage).ceil(),
  2145.                     linesPerPage: _linesPerPage,
  2146.                     showEnglishTransliteration: _showEnglishTransliteration,
  2147.                     showEnglishTranslation: _showEnglishTranslation,
  2148.                     showPunjabiTranslation: _bookNo == 1 ? _showPunjabiTranslation : false,
  2149.                     showPunjabiTeekaTranslation: _showPunjabiTeekaTranslation,
  2150.                     showFaridkotTeekaTranslation: _showFaridkotTeekaTranslation,
  2151.                     showHindiTranslation: _showHindiTranslation,
  2152.                     showHindiTeekaTranslation: _showHindiTeekaTranslation,
  2153.                     language: _language,
  2154.                   isLoading: _isLoading,
  2155.                   showAng: _isNitnem ? false : true,
  2156.                 ),
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.                 ========================================================
  2163.  
  2164.  
  2165.  
  2166.                 BaaniPageView(
  2167.                           baaniLines: _loadSourceLines || _isNitnem ?
  2168.                                       currentAng.baaniLines.length < _pageNo*_linesPerPage ?
  2169.                                           _pageNo >1 ?
  2170.                                             DBResult(
  2171.                                                 baaniLines: currentAng.baaniLines.sublist(
  2172.                                                     (_pageNo-1)*_linesPerPage,
  2173.                                                     (_pageNo)*_linesPerPage >= currentAng.baaniLines.length ?
  2174.                                                       currentAng.baaniLines.length :
  2175.                                                       _pageNo*_linesPerPage
  2176.                                                 ),
  2177.                                                 count: _linesPerPage
  2178.                                             ) :
  2179.                                             DBResult(baaniLines: List.empty(), count: 0) :
  2180.                                       DBResult(
  2181.                                           baaniLines: currentAng.baaniLines.sublist(
  2182.                                               (_pageNo-1)*_linesPerPage,
  2183.                                               (_pageNo)*_linesPerPage >= currentAng.baaniLines.length ?
  2184.                                                 currentAng.baaniLines.length :
  2185.                                                 _pageNo*_linesPerPage
  2186.                                           ),
  2187.                                           count: _linesPerPage
  2188.                                       ) : currentAng,
  2189.                           pageNo: _pageNo,
  2190.                           totalPages: (currentAng.count/_linesPerPage).ceil(),
  2191.                           linesPerPage: _linesPerPage,
  2192.                           showEnglishTransliteration: _showEnglishTransliteration,
  2193.                           showEnglishTranslation: _showEnglishTranslation,
  2194.                           showPunjabiTranslation: _bookNo == 1 ? _showPunjabiTranslation : false,
  2195.                           showPunjabiTeekaTranslation: _showPunjabiTeekaTranslation,
  2196.                           showFaridkotTeekaTranslation: _showFaridkotTeekaTranslation,
  2197.                           showHindiTranslation: _showHindiTranslation,
  2198.                           showHindiTeekaTranslation: _showHindiTeekaTranslation,
  2199.                           language: _language,
  2200.                         isLoading: _isLoading,
  2201.                         showAng: _isNitnem ? false : true,
  2202.                       ),
  2203.  
  2204.  */

Editor

You can edit this paste and save as new:


File Description
  • tilere
  • Paste Code
  • 04 May-2024
  • 92.38 Kb
You can Share it: