Skip to content

Instantly share code, notes, and snippets.

@guid-empty
Last active April 8, 2021 13:56
Show Gist options
  • Save guid-empty/a2dea23663ec4b25d7512a61048254b7 to your computer and use it in GitHub Desktop.
Save guid-empty/a2dea23663ec4b25d7512a61048254b7 to your computer and use it in GitHub Desktop.
Implicit Animations - AnimatedPositioned - Curves
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
const double _logoWidth = 200;
class OtusLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Image.network('https://github.com/flutter-cats/otus-cocktails-application/blob/master/logo-2.8602b.svg'),
width: _logoWidth,
height: 200.0,
color: Colors.green,
);
}
}
class _MyHomePageState extends State<MyHomePage> {
double _left = 0;
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text('Implicit Animations - AnimatedPositioned'),
),
body: Center(
child: Container(
height: 300,
child: Stack(
children: <Widget>[
AnimatedPositioned(
duration: const Duration(seconds: 1),
curve: Curves.bounceOut, // <- curve to set phisics behaviour
left: _left,
child: OtusLogo(),
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_left = _left > 0 ? 0 : size.width - _logoWidth;
});
},
child: Icon(Icons.opacity),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment