Created
June 2, 2021 16:06
-
-
Save HansMuller/d090f2661622d51387ed2986cca4d943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Flutter code sample for AnimatedSize | |
// This example makes a [Container] react to being touched, causing the child | |
// of the [AnimatedSize] widget, here a [FlutterLogo], to animate. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
/// This is the main application widget. | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: Scaffold( | |
appBar: AppBar(title: const Text(_title)), | |
body: const Center( | |
child: MyStatefulWidget(), | |
), | |
), | |
); | |
} | |
} | |
/// This is the stateful widget that the main application instantiates. | |
class MyStatefulWidget extends StatefulWidget { | |
const MyStatefulWidget({Key? key}) : super(key: key); | |
@override | |
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); | |
} | |
/// This is the private State class that goes with MyStatefulWidget. | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> | |
with SingleTickerProviderStateMixin { | |
double _size = 50.0; | |
bool _large = false; | |
void _updateSize() { | |
setState(() { | |
_size = _large ? 250.0 : 100.0; | |
_large = !_large; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTap: () => _updateSize(), | |
child: Container( | |
color: Colors.amberAccent, | |
child: AnimatedSize( | |
vsync: this, | |
curve: Curves.easeIn, | |
duration: const Duration(seconds: 1), | |
child: FlutterLogo(size: _size), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment