Skip to content

Instantly share code, notes, and snippets.

@red-star25
Last active September 26, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/3937866ac53396e52f7eef6fae2107ba to your computer and use it in GitHub Desktop.
Save red-star25/3937866ac53396e52f7eef6fae2107ba to your computer and use it in GitHub Desktop.
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 500),
vsync: this,
upperBound: 650.0,
lowerBound: 400.0,
);
_controller.addListener(() {
setState(() {});
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Image.asset(
"assets/images/area.jpg",
fit: BoxFit.cover,
height: double.infinity,
width: double.infinity,
),
Transform.translate(
offset: Offset(180.0, _controller.value), // <----- here
child: Image.asset(
"assets/images/basketball.png",
height: 70,
width: 70,
fit: BoxFit.contain,
),
)
],
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment