// main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Remove the debug banner
debugShowCheckedModeBanner: false,
title: '坚果前端',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: HomePage());
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
// Create a controller
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: false);
// Create an animation with value of type "double"
late final Animation<double> _animation = CurvedAnimation(
parent: _controller,
curve: Curves.linear,
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('坚果前端'),
),
body: Center(
child: RotationTransition(
turns: _animation,
child: Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: Wrap(
children: [
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.amber, shape: BoxShape.circle),
),
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.green, shape: BoxShape.circle),
),
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.indigo, shape: BoxShape.circle),
),
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.red, shape: BoxShape.circle),
)
],
),
),
),
),
),
// This button is used to toggle the animation
floatingActionButton: FloatingActionButton(
child: Icon(Icons.moving),
onPressed: () {
if (_controller.isAnimating) {
_controller.stop(); // Stop the animation
} else {
_controller.repeat(); // Start the animation
}
},
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
评论