Using this code you can create a beautiful spinning logo app.
Following is the given method for the flutter spinning logo.
import import 'package:flutter/material.dart';
void main() async {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MyApp(),
),
),
);
}
MyApp class extends from a stateful widget. A stateful widget is dynamic: for example, it can change its appearance in response to events triggered by user interactions or when it receives data. Checkbox, Radio, Slider, InkWell, Form, and TextField are examples of stateful widgets. Stateful widgets subclass StatefulWidget.A widget’s state is stored in a State object, separating the widget’s state from its appearance. The state consists of values that can change, like a slider’s current value or whether a checkbox is checked. When the widget’s state changes, the state object calls setState(), telling the framework to redraw the widget.
What's the point?
A stateful widget is implemented by two classes: a subclass of StatefulWidget and a subclass of State.
The state class contains the widget’s mutable state and the widget’s build() method.
When the widget’s state changes, the state object calls setState(), telling the framework to redraw the widget.
Now after understanding the statefulwidget, You will easily understand this example.
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation animation;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: Duration(seconds: 1),
vsync: this,
);
animation = CurvedAnimation(
parent: controller,
curve: Curves.easeInOutCubic,
).drive(Tween(begin: 0, end: 2));
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
controller
..reset()
..forward();
},
child: RotationTransition(
turns: animation,
child: Stack(
children: [
Positioned.fill(
child: FlutterLogo(),
),
Center(
child: Text(
'Click me!',
style: TextStyle(
fontSize: 60.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
);
}
}
0 Comments
Welcome! Please Comment Without Any Hesitation.
Thank You