Code Monkey home page Code Monkey logo

Comments (8)

shivampandey0 avatar shivampandey0 commented on July 3, 2024 1

I was using a single controller in a list. But I tried with the local controller in the list item. It worked.

from screenshot.

shivampandey0 avatar shivampandey0 commented on July 3, 2024

Same here, any solutions?

from screenshot.

SachinGanesh avatar SachinGanesh commented on July 3, 2024

Are you using the same controller multiple times?

from screenshot.

arpit-d avatar arpit-d commented on July 3, 2024

I was using a single controller in a list. But I tried with the local controller in the list item. It worked.

Could you please expand on local controller? How exactly did you use it?

from screenshot.

shivampandey0 avatar shivampandey0 commented on July 3, 2024

I was using a single controller in a list. But I tried with the local controller in the list item. It worked.

Could you please expand on local controller? How exactly did you use it?

It may not be the best solution, but here is what I did.

Previously I made a single controller inside a screen i.e stateful widget and I was using it in the listview item.

To fix the issue. >>>

I made an independent widget for the listview item and made the controller in that widget, So now every item in the listview has its own controller.

from screenshot.

arpit-d avatar arpit-d commented on July 3, 2024

Thanks a lot. Could you please post your code? That would be very helpful!

from screenshot.

peter100u avatar peter100u commented on July 3, 2024

Thanks a lot. Could you please post your code? That would be very helpful!

Thanks a lot. Could you please post your code? That would be very helpful!

from screenshot.

md-rifatkhan avatar md-rifatkhan commented on July 3, 2024

@peter100u define the controller under listview itemBuilder,
the code might look weired but you can check:

              itemScrollController: itemScrollController,
              itemCount: arabicJuzzData.verses?.length ?? 0,
              itemBuilder: (ctx, index) {
                final currentVerse = arabicJuzzData.verses?[index];
                final isMetadata = currentVerse?.textUthmaniTajweed == null;

                if (isMetadata) {
                  final surahNumber = currentVerse!.number!;
                  final surahName = currentVerse.englishName!;
                  surahMap[surahNumber] = surahName;
                  currentJuzzSurahList.add(surahNumber.toString());
                  print("Current Juzz Surah $surahNumber");
                }
                if (isMetadata) {
                  return SurahHeadMeta(
                    containerColor: Colors.blueAccent,
                    englishName: currentVerse!.englishName!,
                    snumber: currentVerse.number!.toString(),
                    relevationType: currentVerse.revelationType!,
                    numberOfAyahs: currentVerse.numberOfAyahs!.toString(),
                    englishTranslation: currentVerse.englishNameTranslation!,
                  );
                } else {
                  final globalKey = GlobalKey();
                  ScreenshotController screenshotController = ScreenshotController();
                  final verseNumber = currentVerse!.verseno!.split(':')[1];
                  final splittedSurah = currentVerse.verseno!.split(':')[0];
                  final editionIndex =
                      cumulativeAyahCount + currentSurahAyahCount;
                  currentSurahAyahCount++;

                  final surahName = surahMap[int.parse(splittedSurah)] ?? '';

                  Color? getContainerColor() {
                    if (currentVerse.obligatory != null &&
                        currentVerse.recommended != null) {
                      if (currentVerse.recommended!) {
                        return const Color(0xff023020);
                      } else if (currentVerse.obligatory!) {
                        return const Color(0xff8B0000);
                      }
                    }
                    return null;
                  }

                  return Screenshot(
                    controller: screenshotController,
                    key: globalKey,
                    child: JuzzReader(
                      onIcon1Pressed: () async {
                        // Capture the screenshot
                        Uint8List? image = await screenshotController.capture(
                            delay: const Duration(milliseconds: 10));

                        // Check if the image capture was successful
                        if (image != null) {
                          try {
                            // Save the image to the device's gallery
                            final result =
                                await ImageGallerySaver.saveImage(image);
                            // Check if image was saved successfully
                            if (result['isSuccess']) {
                              print('Image saved to gallery');
                            } else {
                              print('Failed to save image: ${result['error']}');
                            }
                          } catch (error) {
                            // Error handling if image save fails
                            print('Failed to save image: $error');
                          }
                        } else {
                          // Image capture failed
                          print('Failed to capture image');
                        }
                      },
                      onIcon5Pressed: () {
                        Get.toNamed(tafsir, arguments: {
                          'surahName': RxString(surahName),
                          'surahNumber': splittedSurah,
                          'ayahNumber': int.parse(verseNumber),
                        });
                      },
                      number: int.parse(verseNumber),
                      edition: editionJuzzData[editionIndex].text,
                      showNumber: true,
                      containerColor: getContainerColor(),
                      arabicTextStyle: TextStyle(
                        fontSize: fontsizesForArabic.value,
                        fontFamily: 'uthmanic_hafs',
                      ),
                      arabicText:
                          "${currentVerse.textUthmaniTajweed} ${currentVerse.end}",
                      onIcon4Pressed: () {
                        showDialog(
                          context: context,
                          builder: (context) {
                            return AlertDialog(
                              title: const Text('Copy Text'),
                              content: Column(
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  ListTile(
                                    title: const Text('Copy Arabic Text'),
                                    onTap: () {
                                      Clipboard.setData(
                                        ClipboardData(
                                          text:
                                              currentVerse.textUthmaniTajweed!,
                                        ),
                                      );
                                      ScaffoldMessenger.of(context)
                                          .showSnackBar(
                                        const SnackBar(
                                          content: Text(
                                              'Arabic text copied to clipboard'),
                                        ),
                                      );
                                      Navigator.pop(context);
                                    },
                                  ),
                                  ListTile(
                                    title: const Text('Copy Edition Text'),
                                    onTap: () {
                                      Clipboard.setData(
                                        ClipboardData(
                                          text: editionJuzzData[editionIndex]
                                              .text,
                                        ),
                                      );
                                      ScaffoldMessenger.of(context)
                                          .showSnackBar(
                                        const SnackBar(
                                          content: Text(
                                              'Edition text copied to clipboard'),
                                        ),
                                      );
                                      Navigator.pop(context);
                                    },
                                  ),
                                ],
                              ),
                            );
                          },
                        );
                      },
                    ),
                  );
                }
              },
            );

from screenshot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.