animation struggle
This commit is contained in:
124
lib/main.dart
124
lib/main.dart
@@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/scheduler.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
@@ -14,10 +16,40 @@ class App extends StatefulWidget {
|
|||||||
AppState createState() => AppState();
|
AppState createState() => AppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppState extends State<App> {
|
class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
|
AnimationController _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = AnimationController(
|
||||||
|
duration: Duration(seconds: 3),
|
||||||
|
vsync: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future _startAnim() async {
|
||||||
|
try {
|
||||||
|
await _controller.forward().orCancel;
|
||||||
|
await _controller.reverse().orCancel;
|
||||||
|
} on TickerCanceled {
|
||||||
|
print('welp we fucked');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Material(
|
return Material(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_startAnim();
|
||||||
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
children: [
|
children: [
|
||||||
@@ -26,70 +58,70 @@ class AppState extends State<App> {
|
|||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
ColorFiltered(
|
ColorFiltered(
|
||||||
colorFilter:
|
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.8),
|
||||||
ColorFilter.mode(Colors.black.withOpacity(0.8), BlendMode.srcOut), // This one will create the magic
|
BlendMode.srcOut), // This one will create the magic
|
||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
backgroundBlendMode: BlendMode.dstOut), // This one will handle background + difference out
|
backgroundBlendMode: BlendMode
|
||||||
|
.dstOut), // This one will handle background + difference out
|
||||||
),
|
),
|
||||||
MovingHole(),
|
MovingHole(controller: _controller)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MovingHole extends StatefulWidget {
|
class MovingHole extends StatelessWidget {
|
||||||
@override
|
MovingHole({Key key, this.controller})
|
||||||
MovingHoleState createState() => MovingHoleState();
|
: width = Tween<double>(begin: 50.0, end: 150.0).animate(CurvedAnimation(
|
||||||
}
|
parent: controller,
|
||||||
|
curve: Interval(0.0, 1, curve: Curves.fastOutSlowIn))),
|
||||||
|
height = Tween<double>(begin: 50.0, end: 150.0).animate(CurvedAnimation(
|
||||||
|
parent: controller,
|
||||||
|
curve: Interval(0.0, 1, curve: Curves.fastOutSlowIn))),
|
||||||
|
radius = BorderRadiusTween(
|
||||||
|
begin: BorderRadius.circular(0.0),
|
||||||
|
end: BorderRadius.circular(100.0))
|
||||||
|
.animate(CurvedAnimation(
|
||||||
|
parent: controller,
|
||||||
|
curve: Interval(
|
||||||
|
0.0,
|
||||||
|
1,
|
||||||
|
curve: Curves.ease,
|
||||||
|
))),
|
||||||
|
alignment = AlignmentTween(
|
||||||
|
begin: Alignment.bottomCenter, end: Alignment.topCenter)
|
||||||
|
.animate(CurvedAnimation(
|
||||||
|
parent: controller,
|
||||||
|
curve: Interval(0.0, 1, curve: Curves.ease))),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
class MovingHoleState extends State<MovingHole> {
|
Animation<double> controller;
|
||||||
double _width = 200;
|
Animation<double> width;
|
||||||
double _height = 200;
|
Animation<double> height;
|
||||||
Offset _alignment = Offset(100, 200);
|
Animation<BorderRadius> radius;
|
||||||
bool end = true;
|
Animation<Alignment> alignment;
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Positioned(
|
return AnimatedBuilder(
|
||||||
top: _alignment.dx,
|
animation: controller,
|
||||||
left: _alignment.dy,
|
builder: (BuildContext context, Widget child) {
|
||||||
// alignment: _alignment,
|
return Container(
|
||||||
child: GestureDetector(
|
alignment: alignment.value,
|
||||||
onTap: () async {
|
|
||||||
end == true
|
|
||||||
? Future.delayed(Duration(seconds: 1), () {
|
|
||||||
setState(() {
|
|
||||||
_width = 100;
|
|
||||||
_height = 100;
|
|
||||||
_alignment = Offset(120, 200);
|
|
||||||
end = false;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
: Future.delayed(Duration(seconds: 1), () {
|
|
||||||
setState(() {
|
|
||||||
_width = 200;
|
|
||||||
_height = 200;
|
|
||||||
_alignment = Offset(50, 29);
|
|
||||||
end = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.only(top: 80),
|
width: width.value,
|
||||||
height: _height,
|
height: height.value,
|
||||||
width: _width,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.green,
|
color: Colors.red, borderRadius: radius.value),
|
||||||
borderRadius: BorderRadius.circular(100),
|
));
|
||||||
))));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user