Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. @override
  2. Widget build(BuildContext context) {
  3. return Scaffold(
  4. key: _scaffoldKey,
  5. body: Stack(
  6. children: <Widget>[
  7. FutureBuilder<void>(
  8. future: _initializeControllerFuture,
  9. builder: (context, snapshot) {
  10.  
  11. if (snapshot.connectionState == ConnectionState.done) {
  12. return Stack(
  13. alignment: FractionalOffset.center,
  14. children: <Widget>[
  15. new Positioned.fill(
  16. child: _getCameraPreview(context),
  17. ),
  18. new Positioned.fill(
  19. child: new Opacity(
  20. opacity: 0.7,
  21. child: Image.asset(
  22. _layoutPath,
  23. scale: 5,
  24. fit: BoxFit.none,
  25. alignment: Alignment(0.2, 0.1),
  26. )),
  27. ),
  28. ],
  29. );
  30. } else {
  31. return Center(child: CircularProgressIndicator());
  32. }
  33. },
  34. ),
  35. Align(
  36. alignment: Alignment.bottomCenter,
  37. child: BottomAppBar(
  38. color: Color.fromARGB(0, 0, 0, 0),
  39. child: _getBottomAppBarRow(context),
  40. ),
  41. ),
  42. ],
  43. ),
  44. );
  45. }
  46.  
  47. _getCameraPreview(BuildContext context) {
  48. final size = MediaQuery.of(context).size;
  49. final deviceRatio = size.width / size.height;
  50. return Transform.scale(
  51. scale: _controller.value.aspectRatio / deviceRatio,
  52. child: Center(
  53. child: AspectRatio(
  54. aspectRatio: _controller.value.aspectRatio,
  55. child: CameraPreview(_controller),
  56. ),
  57. ),
  58. );
  59. }
  60.  
  61. final shutterButton = Material(
  62. elevation: 5.0,
  63. borderRadius: BorderRadius.circular(30.0),
  64. color: AppColors.white,
  65. child: FloatingActionButton(
  66. child: Icon(
  67. Icons.camera,
  68. color: AppColors.white,
  69. size: 24,
  70. ),
  71. onPressed: () async {
  72. try {
  73. await _initializeControllerFuture;
  74.  
  75. final path = join(
  76. (await getTemporaryDirectory()).path,
  77. '${DateTime.now()}.png',
  78. );
  79. await _controller.takePicture(path);
  80.  
  81. Navigator.push(
  82. context,
  83. MaterialPageRoute(
  84. builder: (context) => DisplayPictureScreen(imagePath: path),
  85. ),
  86. );
  87. _controller.dispose();
  88. } catch (e) {
  89. print(e);
  90. }
  91. },
  92. ),
  93. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement