|4| Animated Container:
Animated Container:
import 'dart:math'; import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: "Opacity", home: MyHomepage(), ); } } class MyHomepage extends StatefulWidget { @override _MyHomepageState createState() => _MyHomepageState(); } class _MyHomepageState extends State<MyHomepage> { final _rng = Random(); double _height = 100; double _width = 100; double _borderRadius = 8; Color _color = Colors.blue; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Animated Container" ), ), body: Center( child: Padding( padding: EdgeInsets.all(25.0), child: Column( children: <Widget>[ AnimatedContainer( margin: EdgeInsets.all(45), child: FlutterLogo(), // Use the properties stored in the State class. width: this._width, height: this._height, decoration: BoxDecoration( color: this._color, borderRadius: BorderRadius.circular(this._borderRadius), ), duration: Duration(seconds: 1), curve: Curves.fastOutSlowIn, ), RaisedButton.icon( icon: Icon(Icons.update), label: Text('Change Random Property', style: TextStyle( fontSize: 18.0, ), ), onPressed: () => setState( () { // Generate a random width and height. _width = _rng.nextInt(100).toDouble() + 50; _height = _rng.nextInt(100).toDouble() + 50; _borderRadius = _rng.nextInt(50).toDouble(); // Generate a random color. _color = Color.fromRGBO( _rng.nextInt(256), _rng.nextInt(256), _rng.nextInt(256), 1); }, ), ), ], ), ), ), ); } }
Comments
Post a Comment