Last active
February 1, 2024 07:16
-
-
Save yeoupooh/f5a7148bc1e3c2855e555452c01caae2 to your computer and use it in GitHub Desktop.
rotation and scaling in flutter
This file contains hidden or 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. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | |
useMaterial3: true, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
super.key, | |
required this.title, | |
}) : super(); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> | |
with SingleTickerProviderStateMixin { | |
int _counter = 0; | |
var controller; | |
void _incrementCounter() { | |
setState(() { | |
_counter++; | |
}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
controller = AnimationController( | |
vsync: this, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final image = Image.network( | |
'https://docs.flutter.dev/assets/images/dash/dash-fainting.gif'); | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
const Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
Center( | |
child: image, | |
), | |
Center( | |
child: Transform( | |
transform: Matrix4.identity() | |
..scale(1.0, 1.0) | |
..rotateZ(90.0 / 360.0), | |
child: image, | |
), | |
), | |
// Center( | |
// child: RotationTransition( | |
// turns: AlwaysStoppedAnimation(90.0 / | |
// 360), | |
// // Set the initial rotation angle to 90 degrees clockwise | |
// child: ScaleTransition( | |
// scale: Tween<double>(begin: 1, end: 1).animate( | |
// CurvedAnimation( | |
// parent: controller, | |
// curve: Curves.linear, | |
// ), | |
// ), | |
// child: image, | |
// ), | |
// ), | |
// ), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment