Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing Screenshot doesn't work in HookWidget #177

Closed
abdullah-cse opened this issue Apr 26, 2024 · 1 comment
Closed

Capturing Screenshot doesn't work in HookWidget #177

abdullah-cse opened this issue Apr 26, 2024 · 1 comment

Comments

@abdullah-cse
Copy link

In Stateful Widget, Screenshot(this package) works fine, but i have to work with Hook Widget.

In first build, screenshot works fine, but if changing anything in the screen, then capturing screenshot return null value.

Screenshot(
            //Supply the screenshotController to Screenshot widget
            controller: screenshotController,
            child: AnimatedContainer(
              curve: Curves.easeInOutCirc,
              duration: const Duration(milliseconds: 700),
              padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: backGroundColor.value,
                ),
              ),
            child: Text('Hello World'),
            ),
          ),

Here in Hook Widget, i am changing backgroundColor.value from Hook Widget.
After changing anything screenshot package doesn't works.

It only works in first build.

Capturing method is

 onPressed: () async {
                  //Capture the Widget as Image
                  final uint8List = await screenshotController.capture();
                  //Get temp directory to cache it(will be deleted later)
                  String tempPath = (await getTemporaryDirectory()).path;
                  File file = File('$tempPath/image.png');
                  //Save as temporary file
                  await file.writeAsBytes(uint8List!);
                  //Share the temporay saved image with Android/iOS native share dialogue
                  await Share.shareXFiles([XFile(file.path)]);
                },
@abdullah-cse
Copy link
Author

I've solve this problem supplying optional GlobalKey() in ScreenShot widget.

Screenshot(
key:GlobalKey() //By adding this, problem is solved
            //Supply the screenshotController to Screenshot widget
            controller: screenshotController,
            child: AnimatedContainer(
              curve: Curves.easeInOutCirc,
              duration: const Duration(milliseconds: 700),
              padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: backGroundColor.value,
                ),
              ),
            child: Text('Hello World'),
            ),
          ),

But the ui is rebuilding every time i change anything in the screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant