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
Getting "NoSuchMethodError: The method 'toImage' was called on null." Exception #42
Comments
It seems for some reason |
@tehsunnliu Can I get the minimum code to reproduce this issue? Did you wrap your widget with Screenshot Widget? |
@ritheshSalyan Hi, Thank you for your response. First of all my apologies. I should have tested my code more before opening an issue. While I was writing a sample code to reproduce the error I mentioned. I found that I was calling However, this same implementation works fine with RepaintBoundary. I'm not sure how this doesn't affect RepaintBoundary. Anyways below is the code which throws NoSuchMethodError. import 'package:flutter/material.dart';
import 'package:screenshot/screenshot.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _isSaving = false;
List<ScreenshotController> _screenshotControllers = [];
List<Widget> _widgets = [
Card(
child: ListTile(
leading: Icon(
Icons.person,
),
title: Text('Testing Screenshot 1'),
),
),
Card(
child: ListTile(
leading: Icon(
Icons.person,
),
title: Text('Testing Screenshot 2'),
),
),
];
@override
Widget build(BuildContext context) {
_screenshotControllers.clear();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: _widgets.map((e) {
ScreenshotController controller = ScreenshotController();
_screenshotControllers.add(controller);
return Screenshot(
controller: controller,
child: e,
);
}).toList(),
),
),
floatingActionButton: _isSaving
? CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.white),
)
: FloatingActionButton(
onPressed: _saveWidgets,
tooltip: 'Save',
child: Icon(Icons.save),
),
);
}
void _saveWidgets() async {
setState(() {
_isSaving = true;
});
try {
for (int i = _screenshotControllers.length - 1; i >= 0; --i) {
var data =
await _screenshotControllers[i].capture(pixelRatio: 3);
print('ScreenshotData: $data');
}
} catch (e) {
print('failed to capture: $e');
debugPrintStack();
}
setState(() {
_isSaving = false;
});
}
} |
@tehsunnliu The code you have shared is working perfectly fine, It didn't throw any error, Can I know your flutter version? You can close this issue if it is working. |
Oh, I don't know why it's happening with me with the same code I haven't changed anything. Have you tried on debug mode? |
|
screenshot: ^0.2.0
was working perfectly fine till I updated Flutter to 2.0 and Screenshot Package toscreenshot: ^1.0.0-nullsafety.1
I started getting "NoSuchMethodError: The method 'toImage' was called on null." exception.I'm calling
screenshotController.capture()
method.The exception is thrown inside
captureAsUiImage()
method when it tries to callboundary.toImage(...);
This happens when I try to capture multiple widgets screenshot.
I've multiple
CardView
inside aColumn
which is wrapped withScreenshot
widget. When I try to all.capture()
for eachScreenshotController
only the first call tocapture
works and for the rest it throwsNoSuchMethodError
I've also tried increasing the delay, however, no success.
The text was updated successfully, but these errors were encountered: