How to take a screenshot of the current widget - Flutter

前端 未结 4 690
感动是毒
感动是毒 2020-12-01 06:02

I need to take a screenshot of the current screen or widget and I need to write it into a file.

4条回答
  •  -上瘾入骨i
    2020-12-01 06:11

    This answer applies if you want to take a screenshot of the widget outside of your dart code.

    To take a screenshot of your widget, make sure your dart file has a void main() async { function.

    From the terminal, go to your app folder, and run your widget, like this:

    flutter run lib/my_test.dart
    

    Or if you want to run your entire app, just run:

    flutter run
    

    Then your widget will start.

    Press the s key to print a screenshot.

    You will see a message like this:

    Taking screenshot for SM S757BL... 1,580ms Screenshot written to flutter_01.png (38kB).

    The image is saved in your app folder.

提交回复
热议问题