Home > Blockchain >  NoSuchMethodError when taking Screenshot
NoSuchMethodError when taking Screenshot

Time:08-13

I am trying to take a Screanshot of a Stak with a list of iteams in it. It displays normaly and works, but when i try to take screenshot of the Widget I resive: NoSuchMethodError (NoSuchMethodError: The getter 'stateWidget' was called on null. Receiver: null Tried calling: stateWidget) (I use a Inhereted widget)

Her is the Widget I am trying to take a Screenshot of

class BlinkSkjerm extends StatelessWidget {

@override Widget build(BuildContext context) {

final provider = InheritedDataProvider.of(context); final data = provider.historikken[provider.index];

return SizedBox(
    height: 400,
    child: Stack(
      children: data.inMoveableItemsList,
    ));

} }

and her is the onPress funtion:

onPressed: () async {
    final controler = ScreenshotController();
    final bytes = await controler.captureFromWidget(BlinkSkjerm());
    setState(() {
      this.bytes = bytes;
    });
  }

CodePudding user response:

you used InheritedDataProvider in wrong way. you did not provide data that needed in BlinkSkjerm.

you want to take screen shot from widget that not in the tree, but that widget need data that should provide before build it which you did not provide it.

this approach work this way:

Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => InheritedDataProvider(
                        child: BlinkSkjerm(),
                        data:'some string',
                      )),
                ); 

this way you can use

final provider = InheritedDataProvider.of(context);

and make sure it is not null.

for your situation I recommended to do something like this:

onPressed: () async {
    final controler = ScreenshotController();
    final bytes = await controler.captureFromWidget(InheritedDataProvider(
                            child: BlinkSkjerm(),
                            data:'some string',
                          ));
    setState(() {
      this.bytes = bytes;
    });
  }

for more information see this page

  • Related