Last active
November 8, 2023 19:45
-
-
Save ZnZq/589591d7ac7d7dea5bcbc3969a144fc7 to your computer and use it in GitHub Desktop.
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
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
// ignore_for_file: prefer_const_constructors | |
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MainApp()); | |
class MainApp extends StatefulWidget { | |
const MainApp({super.key}); | |
@override | |
State<MainApp> createState() => _MainAppState(); | |
} | |
class _MainAppState extends State<MainApp> { | |
Offset _offset = Offset.zero; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text(_offset.toString()), | |
actions: [ | |
IconButton( | |
onPressed: () { | |
setState(() => _offset = Offset.zero); | |
}, | |
icon: Icon(Icons.restore), | |
) | |
], | |
), | |
body: GestureDetector( | |
onPanUpdate: (details) { | |
setState(() => _offset += details.delta); | |
}, | |
child: Container( | |
color: Colors.red, | |
height: double.infinity, | |
width: double.infinity, | |
child: SingleChildScrollView( | |
child: Column( | |
children: [ | |
for (int i = 0; i < 2; i++) Layer(cubeSize: 32, size: 7) | |
], | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class Layer extends StatelessWidget { | |
final double cubeSize; | |
final int size; | |
const Layer({Key? key, required this.cubeSize, required this.size}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: cubeSize * size, | |
height: cubeSize * size, | |
color: Colors.orange, | |
child: Transform( | |
transform: Matrix4.identity()..translate(75.0, 125.0, 0.0)..rotateX(-0.4)..rotateY(0.8), | |
alignment: Alignment.center, | |
child: Stack( | |
children: [ | |
Transform( | |
transform: Matrix4.identity()..translate(0.0, 0.0, 0.0)..rotateX(-pi / 2), | |
child: SizedBox( | |
width: cubeSize * size, | |
height: cubeSize * size, | |
child: Stack( | |
children: [ | |
for (var x = 0; x < size; x++) | |
for (var y = 0; y < size; y++) | |
Positioned( | |
left: x * cubeSize, | |
top: y * cubeSize, | |
width: cubeSize, | |
height: cubeSize, | |
child: SizedBox( | |
width: cubeSize, | |
height: cubeSize, | |
child: const Image( | |
image: AssetImage('assets/block_top.jpg'), | |
fit: BoxFit.contain, | |
filterQuality: FilterQuality.none, | |
), | |
), | |
) | |
], | |
), | |
), | |
), | |
Transform( | |
transform: Matrix4.identity()..translate(0.0, 0.0, 0.0)..rotateY(pi / 2), | |
child: Stack( | |
children: [ | |
for (var x = 0; x < size; x++) | |
Positioned( | |
left: x * cubeSize, | |
width: cubeSize, | |
height: cubeSize, | |
child: SizedBox( | |
width: cubeSize, | |
height: cubeSize, | |
child: const Image( | |
image: AssetImage('assets/block_side.jpg'), | |
fit: BoxFit.contain, | |
filterQuality: FilterQuality.none, | |
), | |
), | |
) | |
], | |
), | |
), | |
Transform( | |
transform: Matrix4.identity()..translate(0.0, 0.0, 0.0)..rotateY(0), | |
child: Stack( | |
children: [ | |
for (var x = 0; x < size; x++) | |
Positioned( | |
left: x * cubeSize, | |
width: cubeSize, | |
height: cubeSize, | |
child: SizedBox( | |
width: cubeSize, | |
height: cubeSize, | |
child: const Image( | |
image: AssetImage('assets/block_side.jpg'), | |
fit: BoxFit.contain, | |
filterQuality: FilterQuality.none, | |
), | |
), | |
) | |
], | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment