Created
January 5, 2021 21:22
-
-
Save mingsai/4cdd6a0d6c6a740dab7604c62b858807 to your computer and use it in GitHub Desktop.
Flutter screen capture example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui' as ui; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:rtjf/components/home_content.dart'; | |
class HomeScreen extends StatefulWidget { | |
static const String id = '/home_screen'; | |
@override | |
_HomeScreenState createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> | |
with SingleTickerProviderStateMixin { | |
static GlobalKey screen = new GlobalKey(); | |
AnimationController _controller; | |
@override | |
void initState() { | |
_controller = AnimationController(vsync: this); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return SafeArea( | |
child: GestureDetector( | |
behavior: HitTestBehavior.translucent, | |
onTap: () async { | |
print('touched'); | |
}, | |
child: RepaintBoundary( | |
key: screen, | |
child: Container( | |
color: Colors.white, | |
child: HomeContent(), | |
), | |
), | |
), | |
); | |
} | |
Future<ui.Image> screenCapture() async { | |
RenderRepaintBoundary boundary = screen.currentContext.findRenderObject(); | |
return await boundary.toImage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment