/// This example is slightly adapted from /// https://medium.com/flutter-community/advanced-flutter-matrix4-and-perspective-transformations-a79404a0d828 /// and /// https://medium.com/flutter/perspective-on-flutter-6f832f4d912e /// import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Perspective', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: const PerspectiveDemo(), ); } } class PerspectiveDemo extends StatefulWidget { const PerspectiveDemo({Key? key}) : super(key: key); @override _PerspectiveDemoState createState() => _PerspectiveDemoState(); } class _PerspectiveDemoState extends State { double x = 0; double y = 0; double z = 0; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Transform( transform: Matrix4( 1, 0, 0, 0, // for formatting 0, 1, 0, 0, 0, 0, 1, 0.001, 0, 0, 0, 1, ) ..rotateX(x) ..rotateY(y) ..rotateZ(z), alignment: FractionalOffset.center, child: GestureDetector( onPanUpdate: (details) { setState(() { y = y - details.delta.dx / 100; x = x + details.delta.dy / 100; }); }, child: Container( color: Colors.black, height: 200.0, width: 200.0, child: Center( child: Container( height: 100, width: 100, color: Colors.blue, child: const Center( child: Text('Hello, world!'), ), ), ), ), ), ), ), ); } }