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

renderFlutterWidget error #160

Open
hyeonhh opened this issue Sep 19, 2023 · 1 comment
Open

renderFlutterWidget error #160

hyeonhh opened this issue Sep 19, 2023 · 1 comment

Comments

@hyeonhh
Copy link

hyeonhh commented Sep 19, 2023

https://codelabs.developers.google.com/flutter-home-screen-widgets#5

I'm following the Rendering Flutter Widgets as an image process in Codelab above.

floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
if (_globalKey.currentContext != null) {
var path = await HomeWidget.renderFlutterWidget(
const LineChart(),
**fileName: 'screenshot',** //1. error occurs
key: 'filename',
**logicalSize: _globalKey.currentContext!.size**, // 2. error occurs
pixelRatio:
MediaQuery.of(_globalKey.currentContext!).devicePixelRatio,
);
setState(() {
imagePath = path as String?;
});
}
updateHeadline(widget.article);
},
label: const Text('Update Homescreen'),
),

There's an error with the code above

At this time, HomeWidget.renderFlutterWidget has an error with fileName and logicalSize

  1. For fileName
    The named parameter 'fileName' isn't defined.
    Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'fileName'
    I got this error

  2. About logicalSize
    The argument type 'Size?' can't be assigned to the parameter type 'Size'.
    I got this error

So we're going to get rid of the two people who have errors

floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
if (_globalKey.currentContext != null) {
var path = await HomeWidget.renderFlutterWidget(
const LineChart(),
key: 'filename',
pixelRatio:
MediaQuery.of(_globalKey.currentContext!).devicePixelRatio,
);
setState(() {
imagePath = path as String?;
});
}
updateHeadline(widget.article);
},
label: const Text('Update Homescreen'),
),

The error below occurred because I executed the code as above.

Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'C:\tools\flutter\bin\flutter.bat'' finished with non-zero exit value 1

What should I do?

@ABausG
Copy link
Owner

ABausG commented Sep 21, 2023

Oh. Seems like the Codelab still uses an older Version of this Feature. @leighajarett can you update that?

@hyeonhh For your Issue:

  • You need to provide the key that will be used as the filename
  • You need to provide the size you want the picture to be taken

As a backstory: The First Version of this could only save widgets that were already present in the widget tree. But we changed it such that you can render Widgets that you don't add to the main app's Widget tree

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

2 participants