이미지를 표시하고, 아래 버튼을 누르면 회전하게 하는 코드
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
double _angle = 0.0;
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: this,
);
}
void _incrementCounter() {
setState(() {
_angle += pi / 50;
print(_angle);
});
_controller.forward(from: 0.0);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('data'),
leading: const Icon(Icons.abc),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You',
),
SizedBox(
child: AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Transform.rotate(
angle: _angle,
child: Image.asset(
'repo/images/img1.png',
),
);
},
),
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
backgroundColor: Colors.amber,
child: const Icon(Icons.add),
),
);
}
}
'flutter_프로젝트 > 0_초보_코드모음' 카테고리의 다른 글
flutter 코드모음 - sqflite db 에 값 추가 (0) | 2025.05.29 |
---|---|
flutter 코드모음 : sqflite - SQL db생성 (0) | 2025.05.25 |
flutter 코드모음 - 로컬에서 json 읽어오기 (0) | 2025.03.23 |
flutter 코드 모음 - class 의 가장 간단한 예 (0) | 2025.03.16 |
dart : 클레스 (0) | 2025.03.05 |